Skip to content

Commit 0237b06

Browse files
authored
Consolidate documentation on config folder (#345)
The semantics around `klog config` and `klog info config-folder` are a bit confusing. This PR consolidates all config-related documentation into the `klog config` command. `klog info config-folder` has now become `klog config --location`.
1 parent 7b3cc55 commit 0237b06

File tree

4 files changed

+45
-58
lines changed

4 files changed

+45
-58
lines changed

klog/app/cli/bookmarks.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ A bookmark name is denoted by the prefix '@'. For example, if you have a bookmar
3535
klog edit @work
3636
3737
You can specify as many bookmarks as you want. There can also be one “unnamed” default bookmark (which internally is identified by the name '@default').
38-
This is useful in case you only have one main file at a time, and allows you to use klog without any input arguments at all. E.g.:
38+
This is useful in case you only have one main file at a time, and allows you to use klog without any file-related input arguments at all. E.g.:
3939
4040
klog total
4141
klog start --summary 'Started new project'
4242
43-
When creating a bookmark, you can also create the respective target file by using the '--create' flag.
43+
When setting up a bookmark, you can also create the respective target file on the file system by using the '--create' flag.
44+
45+
Note that klog keeps track of the bookmarks in an internal config file. Run 'klog config --help' to learn more.
4446
`
4547
}
4648

klog/app/cli/config.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,45 @@ import (
44
"github.com/jotaen/klog/klog/app"
55
tf "github.com/jotaen/klog/klog/app/cli/terminalformat"
66
"github.com/jotaen/klog/klog/app/cli/util"
7+
"path/filepath"
8+
"strings"
79
)
810

911
type Config struct {
12+
Location bool `name:"location" help:"Print the location of the config folder."`
1013
util.NoStyleArgs
1114
}
1215

1316
func (opt *Config) Help() string {
17+
lookupOrder := func() string {
18+
lookups := make([]string, len(app.KLOG_CONFIG_FOLDER))
19+
for i, f := range app.KLOG_CONFIG_FOLDER {
20+
lookups[i] = filepath.Join(f.EnvVarSymbol(), f.Location)
21+
}
22+
return strings.Join(lookups, " -> ")
23+
}()
24+
1425
return `
15-
You are able to configure some of klog’s behaviour by providing a configuration file.
26+
klog relies on file-based configuration to customise some of its default behaviour and to keep track of its internal state.
1627
17-
If you run 'klog config', you can learn about the supported properties in the file, and which of those you have set.
18-
You may use the output of that command as template for setting up your config file, as its format is valid syntax.
28+
Run 'klog config --location' to print the path of the folder where klog looks for the configuration.
29+
The config folder can contain one or both of the following files:
30+
- '` + app.CONFIG_FILE_NAME + `': you can create this file manually to override some of klog’s default behaviour. You may use the output of the 'klog config' command as template for setting up this file, as its output is in valid syntax.
31+
- '` + app.BOOKMARKS_FILE_NAME + `': if you use the bookmarks functionality, then klog uses this file as database. You are not supposed to edit this file by hand! Instead, use the 'klog bookmarks' command to manage your bookmarks.
1932
20-
The configuration file is named 'config.ini' and resides in your klog config folder.
21-
Run 'klog info config-folder' to learn where your klog config folder is located.
33+
You can customise the location of the config folder via environment variables. klog uses the following lookup precedence:
34+
` + lookupOrder + `
2235
`
2336
}
2437

2538
func (opt *Config) Run(ctx app.Context) app.Error {
2639
opt.NoStyleArgs.Apply(&ctx)
40+
41+
if opt.Location {
42+
ctx.Print(ctx.KlogConfigFolder().Path() + "\n")
43+
return nil
44+
}
45+
2746
styler, _ := ctx.Serialise()
2847
for i, e := range app.CONFIG_FILE_ENTRIES {
2948
ctx.Print(styler.Props(tf.StyleProps{Color: tf.TEXT_SUBDUED}).Format(util.Reflower.Reflow(e.Help.Summary, []string{"# "})))

klog/app/cli/index.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
kc "github.com/jotaen/kong-completion"
99
)
1010

11+
var INTRO_SUMMARY = "klog is a command-line tool for time tracking in a human-readable, plain-text file format.\nSee " + KLOG_WEBSITE_URL + " for documentation.\n"
12+
1113
// Guideline for help texts and descriptions:
1214
// - Command and flag descriptions are phrased in imperative style, and they
1315
// end in a period. Examples:
@@ -54,11 +56,10 @@ type Default struct {
5456
}
5557

5658
func (opt *Default) Help() string {
57-
return `
58-
klog: command line app for time tracking with plain-text files. See also ` + KLOG_WEBSITE_URL + `
59+
return INTRO_SUMMARY + `
5960
6061
Time-tracking data is stored in files ending in the '.klg' extension.
61-
You can use the subcommands below to evaluate, manipulate and manage your files.
62+
You can use the subcommands listed below to evaluate, manipulate and manage your files.
6263
Use the '--help' flag on the subcommands to learn more.
6364
6465
You can specify input data in one of these 3 ways:
@@ -80,7 +81,7 @@ func (opt *Default) Run(ctx app.Context) app.Error {
8081
versionCmd := Version{}
8182
return versionCmd.Run(ctx)
8283
}
83-
ctx.Print("klog: command line app for time tracking with plain-text files.\n")
84+
ctx.Print(INTRO_SUMMARY)
8485
ctx.Print("Run 'klog --help' to learn usage.\n")
8586
return nil
8687
}

klog/app/cli/info.go

Lines changed: 12 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,23 @@ package cli
22

33
import (
44
"github.com/jotaen/klog/klog/app"
5-
"github.com/jotaen/klog/klog/app/cli/util"
6-
"path/filepath"
7-
"strings"
85
)
96

107
type Info struct {
11-
Spec InfoSpec `cmd:"" name:"spec" help:"Print the .klg file format specification."`
12-
License InfoLicense `cmd:"" name:"license" help:"Print license / copyright information."`
13-
ConfigFolder InfoConfigFolder `cmd:"" name:"config-folder" help:"Print the path of the klog config folder."`
8+
Spec bool `name:"spec" help:"Print the .klg file format specification."`
9+
License bool `name:"license" help:"Print license / copyright information."`
10+
About bool `name:"about" help:"Print meta information about klog."`
1411
}
1512

16-
func (opt *Info) Help() string {
17-
return `
18-
Run 'klog info config-folder' to see the location of your klog config folder.
19-
The location of the config folder depends on your operating system and environment settings.
20-
You can customise the folder’s location via environment variables – run the command to learn which ones klog relies on.
21-
22-
The config folder is used to store two files:
23-
- 'config.ini' (optional) – you can create this file manually to override some of klog’s default behaviour. Run 'klog config' to learn more.
24-
- 'bookmarks.json' (optional) – if you use bookmarks, then klog uses this file as database. You are not supposed to edit this file by hand! Instead, use the 'klog bookmarks' command to manage your bookmarks.
25-
26-
Run 'klog info spec' to read the formal specification of the klog file format.
27-
If you want to review klog’s license and copyright information, run 'klog info license'.
28-
`
29-
}
30-
31-
type InfoConfigFolder struct {
32-
util.QuietArgs
33-
}
34-
35-
func (opt *InfoConfigFolder) Run(ctx app.Context) app.Error {
36-
ctx.Print(ctx.KlogConfigFolder().Path() + "\n")
37-
if !opt.Quiet {
38-
lookups := make([]string, len(app.KLOG_CONFIG_FOLDER))
39-
for i, f := range app.KLOG_CONFIG_FOLDER {
40-
lookups[i] = filepath.Join(f.EnvVarSymbol(), f.Location)
41-
}
42-
ctx.Print("(Lookup order: " + strings.Join(lookups, ", ") + ")\n")
13+
func (opt *Info) Run(ctx app.Context) app.Error {
14+
if opt.Spec {
15+
ctx.Print(ctx.Meta().Specification + "\n")
16+
} else if opt.License {
17+
ctx.Print(ctx.Meta().License + "\n")
18+
} else if opt.About {
19+
ctx.Print(INTRO_SUMMARY)
20+
} else {
21+
ctx.Print("Use --spec or --license\n")
4322
}
4423
return nil
4524
}
46-
47-
type InfoSpec struct{}
48-
49-
func (opt *InfoSpec) Run(ctx app.Context) app.Error {
50-
ctx.Print(ctx.Meta().Specification + "\n")
51-
return nil
52-
}
53-
54-
type InfoLicense struct{}
55-
56-
func (opt *InfoLicense) Run(ctx app.Context) app.Error {
57-
ctx.Print(ctx.Meta().License + "\n")
58-
return nil
59-
}

0 commit comments

Comments
 (0)