-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for reading config from a file
- Loading branch information
Showing
9 changed files
with
141 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ punchout | |
debug.log | ||
punchout.v*.db | ||
.quickrun | ||
justfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/BurntSushi/toml" | ||
) | ||
|
||
type JiraConfig struct { | ||
JiraURL *string `toml:"jira_url"` | ||
JiraToken *string `toml:"jira_token"` | ||
Jql *string | ||
JiraTimeDeltaMins *int `toml:"jira_time_delta_mins"` | ||
} | ||
|
||
type POConfig struct { | ||
DbPath *string `toml:"db_path"` | ||
Jira JiraConfig | ||
} | ||
|
||
func readConfig(filePath string) (POConfig, error) { | ||
|
||
var config POConfig | ||
_, err := toml.DecodeFile(expandTilde(filePath), &config) | ||
if err != nil { | ||
return config, err | ||
} | ||
if config.DbPath != nil { | ||
*config.DbPath = expandTilde(*config.DbPath) | ||
} | ||
|
||
return config, nil | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
"os/user" | ||
"strings" | ||
) | ||
|
||
func expandTilde(path string) string { | ||
if strings.HasPrefix(path, "~") { | ||
usr, err := user.Current() | ||
if err != nil { | ||
os.Exit(1) | ||
} | ||
return strings.Replace(path, "~", usr.HomeDir, 1) | ||
} | ||
return path | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters