Skip to content

Commit 060ff77

Browse files
authored
Add support for environment variable to specify config file path (#858)
1 parent fc833bf commit 060ff77

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,15 @@ default.
125125
#### Shell completion
126126
Check `jira completion --help` for more info on setting up a bash/zsh shell completion.
127127

128+
#### Multiple projects
129+
130+
The tool honors the `JIRA_CONFIG_FILE` environment variable, which specifies the location of the configuration file:
131+
132+
```sh
133+
JIRA_CONFIG_FILE=./local_jira_config.yaml jira issue list
134+
135+
```
136+
128137
## Usage
129138
The tool currently comes with an issue, epic, and sprint explorer. The flags are [POSIX-compliant](https://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html).
130139
You can combine available flags in any order to create a unique query. For example, the command below will give you high priority issues created this month

internal/cmd/root/root.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,13 @@ var (
4242
func init() {
4343
cobra.OnInitialize(func() {
4444
if config != "" {
45+
// 1. Command line flag has the highest priority
4546
viper.SetConfigFile(config)
47+
} else if configFile := os.Getenv("JIRA_CONFIG_FILE"); configFile != "" {
48+
// 2. Environment variable has second priority
49+
viper.SetConfigFile(configFile)
4650
} else {
51+
// 3. Default location has the lowest priority
4752
home, err := cmdutil.GetConfigHome()
4853
if err != nil {
4954
cmdutil.Failed("Error: %s", err)
@@ -98,7 +103,7 @@ func NewCmdRoot() *cobra.Command {
98103

99104
cmd.PersistentFlags().StringVarP(
100105
&config, "config", "c", "",
101-
fmt.Sprintf("Config file (default is %s/%s/%s.yml)", configHome, jiraConfig.Dir, jiraConfig.FileName),
106+
fmt.Sprintf("Config file (default is %s/%s/%s.yml, can be overridden with JIRA_CONFIG_FILE env var)", configHome, jiraConfig.Dir, jiraConfig.FileName),
102107
)
103108
cmd.PersistentFlags().StringP(
104109
"project", "p", "",

0 commit comments

Comments
 (0)