-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce file-based user configuration
This PR addresses #158. klog now looks for a config file at `~/.klog/config.yml`, where users are able to specify some preferences. For now, that is: - `default_rounding`: the value for the `--round` flag, unless specified, e.g. in `klog start` or `klog stop`. - `default_should_total`: the default for the `--should-total` flag, unless specified, that is used whenever klog creates a new record, e.g. in `klog create`, but also in `klog track` or `klog start`, as these might create new records on the fly. More configuration parameters may follow later, now that the groundwork is set up. When the config file is absent, everything behaves as before, so it’s strictly optional right now. What’s also new is that klog will respect the `$KLOG_FOLDER_LOCATION` or `$XDG_CONFIG_HOME` environment variables, if set. In this case, **and** when users have bookmarks, then this will be a breaking change. The fix is for them to manually move over their `bookmarks.json` file to the new klog folder location. I’ll take note in the Changelog about this. The `klog config` command is hidden from the help output for now, but it can be invoked nevertheless on the nightly build (when compiling klog from the `main` branch). I’ll do some more testing, refactoring, and enhancements in the next time, and plan to include this with the next release – probably within the next few weeks.
- Loading branch information
Showing
24 changed files
with
652 additions
and
138 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
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,36 @@ | ||
package cli | ||
|
||
import ( | ||
"github.com/jotaen/klog/klog/app" | ||
"github.com/jotaen/klog/klog/app/cli/lib" | ||
"github.com/jotaen/klog/klog/app/cli/lib/terminalformat" | ||
) | ||
|
||
type Config struct { | ||
ConfigFilePath bool `name:"file-path" help:"Prints the path to your config file"` | ||
} | ||
|
||
func (opt *Config) Help() string { | ||
return `You are able to configure some of klog’s behaviour via a YAML file in your ` + "`" + app.KLOG_FOLDER_NAME + "`" + ` folder. (Run ` + "`" + `klog config --file-path` + "`" + ` to print the exact location.) | ||
If you run ` + "`" + `klog config` + "`" + `, you can learn about the supported YAML properties in the file, and you also see what values are in effect at the moment. | ||
Note: the output of the command does not print the actual file. You may, however, use the output as template for setting up the file, as its YAML-formatted.` | ||
} | ||
|
||
func (opt *Config) Run(ctx app.Context) app.Error { | ||
if opt.ConfigFilePath { | ||
ctx.Print(app.Join(ctx.KlogFolder(), app.CONFIG_FILE_NAME).Path() + "\n") | ||
return nil | ||
} | ||
for i, e := range app.CONFIG_FILE_ENTRIES { | ||
ctx.Print(lib.Subdued.Format(lib.Reflower.Reflow(e.Description+"\n"+e.Instructions, "# "))) | ||
ctx.Print("\n") | ||
ctx.Print(lib.Red.Format(e.Name) + `: ` + terminalformat.Style{Color: "227"}.Format(e.Value(ctx.Config()))) | ||
if i < len(app.CONFIG_FILE_ENTRIES)-1 { | ||
ctx.Print("\n\n") | ||
} | ||
} | ||
ctx.Print("\n") | ||
return 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
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
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
Oops, something went wrong.