Skip to content

Commit 721461d

Browse files
committed
feat: Unattended mode
1 parent 7f8b8fa commit 721461d

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,20 @@ You can specify the tag of the release you want to install. If you don't specify
5151
gah install getsops/sops --tag=v3.10.2
5252
```
5353

54-
### Using default names
54+
### Unattended mode
5555

56-
If you want to use the default names for the installed binaries, you can use the `--use-default-names` flag. This is specially useful for unattended installations, where you don't want to be prompted for the name of the binary.
56+
`gah` will try to detect if your terminal supports input or not. To force this behavior you can either use the `--unattended` flag or set env var `UNATTENDED=true`.
57+
This will skip the confirmation prompt and install the app without asking for any input.
5758

5859
```bash
59-
gah install getsops/sops --use-default-names
60+
gah install getsops/sops --unattended
61+
```
62+
63+
or
64+
65+
```bash
66+
export UNATTENDED=true
67+
gah install getsops/sops
6068
```
6169

6270
### Update gah

gah

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ set -e
1414
VERSION="v1.1.0"
1515
HELP_STRING="Type 'gah help' to show help."
1616

17+
if [ ! -t 0 ]; then
18+
UNATTENDED="true"
19+
fi
20+
1721
if [[ -z "$GAH_CACHE_DIR" ]]; then
1822
GAH_CACHE_DIR="$HOME/.cache/gah"
1923
fi
@@ -274,7 +278,6 @@ function command_install() {
274278

275279
local repo="$1"
276280
local tag="$2"
277-
local use_default_names="$3"
278281

279282
# Fetch the release information
280283
print_blue "Fetching release info for: $repo [$tag]"
@@ -286,14 +289,24 @@ function command_install() {
286289

287290
# Check if several download URLs were found
288291
if [[ $(echo "$download_url" | wc -l) -gt 1 ]]; then
289-
print_yellow "Several download URLs were found which match your OS and arch. Please select one:"
290-
select url in $download_url; do
291-
download_url=$url
292-
break
293-
done
292+
print_yellow "Several download URLs were found which match your OS and arch."
293+
294+
if [[ "$UNATTENDED" == "true" ]]; then
295+
# Select the first one
296+
download_url=$(echo "$download_url" | head -n 1)
297+
print_yellow "Unattended mode, so using the first download URL: $download_url"
298+
299+
else
300+
print_yellow "Please select one:"
301+
select url in $download_url; do
302+
download_url=$url
303+
break
304+
done
305+
306+
if [[ -z "$download_url" ]]; then
307+
throw_error 14 "No download URL was selected"
308+
fi
294309

295-
if [[ -z "$download_url" ]]; then
296-
throw_error 14 "No download URL was selected"
297310
fi
298311
fi
299312

@@ -334,7 +347,7 @@ function command_install() {
334347

335348
print_blue "Installing: $file_name"
336349

337-
if [[ -n "$use_default_names" ]]; then
350+
if [[ "$UNATTENDED" == "true" ]]; then
338351
print_yellow "Using default name: $file_name"
339352
else
340353
print_yellow "Give a new name or keep '$file_name'? (Leave empty to keep the same)"
@@ -428,7 +441,6 @@ function main() {
428441

429442
# Default values for optional parameters
430443
local tag="latest"
431-
local use_default_names=""
432444

433445
# Parse optional parameters
434446
while [[ $# -gt 0 ]]; do
@@ -437,8 +449,8 @@ function main() {
437449
tag="${3#--tag=}"
438450
shift 1
439451
;;
440-
--use-default-names)
441-
use_default_names="1"
452+
--unattended)
453+
UNATTENDED="true"
442454
shift 1
443455
;;
444456
*)
@@ -448,7 +460,7 @@ function main() {
448460
done
449461

450462
# Use the parsed tag and default_names
451-
command_install "$repo" "$tag" "$use_default_names"
463+
command_install "$repo" "$tag"
452464

453465
elif [[ "$1" == "aliases" ]]; then
454466
if [[ "$2" == "show" ]]; then

0 commit comments

Comments
 (0)