Skip to content

Commit 86e7308

Browse files
committed
add env vars
1 parent 0973f4c commit 86e7308

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

README.md

+4-6
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ Set up your arguments, eg
3535
fetch --files=puzzle.md --ide=goland --year=2020 --day=01 --template=template
3636
```
3737

38-
Optionally create an alias run quicker
39-
```shell
40-
alias f="fetch --files=puzzle.md --ide=goland --template=template"
41-
```
42-
43-
Optionally provide
38+
The following env vars are also supported to override default values
39+
- `FETCH_TEMPLATE`
40+
- `FETCH_FILES`
41+
- `FETCH_IDE`

main.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ var files string
2121
func main() {
2222
flag.IntVar(&day, "day", today(), "day to download puzzle for")
2323
flag.IntVar(&year, "year", time.Now().Year(), "year to download puzzle for")
24-
flag.StringVar(&template, "template", "template", "template folder")
25-
flag.StringVar(&ide, "ide", "goland", "ide command to open files, must support opening files like \"$ {IDE} example\"")
26-
flag.StringVar(&files, "files", "puzzle.md", "comma seperated list of files to open automatically")
24+
flag.StringVar(&template, "template", osOr("FETCH_TEMPLATE", "template"), "template folder")
25+
flag.StringVar(&ide, "ide", osOr("FETCH_IDE", "goland"), "ide command to open files, must support opening files like \"$ {IDE} example\"")
26+
flag.StringVar(&files, "files", osOr("FETCH_FILES", "puzzle.md"), "comma seperated list of files to open automatically")
2727
flag.Parse()
2828

2929
if year < 100 {
@@ -76,3 +76,10 @@ func today() int {
7676
}
7777
return d
7878
}
79+
80+
func osOr(env string, def string) string {
81+
if val := os.Getenv(env); val != "" {
82+
return val
83+
}
84+
return def
85+
}

0 commit comments

Comments
 (0)