From b1eea83d4950a7e73038afa38e073f8002b71485 Mon Sep 17 00:00:00 2001 From: Egor Kovetskiy Date: Mon, 23 Aug 2021 13:20:18 +0600 Subject: [PATCH] add config parameter --- README.md | 9 ++++----- main.go | 12 ++++++++---- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index dcc1e63..825a2f5 100644 --- a/README.md +++ b/README.md @@ -342,8 +342,7 @@ mark -h | --help - `-b ` or `--base-url ` – Base URL for Confluence. Alternative option for `base_url` config field. - `-f ` — Use specified markdown file(s) for converting to html. Supports file globbing patterns (needs to be quoted). -- `-c ` — Specify configuration file which should be used for reading - Confluence page URL and markdown file path. +- `-c ` or `--config ` — Specify a path to the configuration file. - `-k` — Lock page editing to current user only to prevent accidental manual edits over Confluence Web UI. - `--drop-h1` – Don't include H1 headings in Confluence output. @@ -354,11 +353,11 @@ mark -h | --help - `-h | --help` — Show help screen and call 911. You can store user credentials in the configuration file, which should be -located in ~/.config/mark with the following format (TOML): +located in ~/.config/mark (or specified via `-c --config `) with the following format (TOML): ```toml -username = "smith" -password = "matrixishere" +username = "your-email" +password = "password-or-api-key-for-confluence-cloud" # If you are using Confluence Cloud add the /wiki suffix to base_url base_url = "http://confluence.local" ``` diff --git a/main.go b/main.go index 51406cc..e880459 100644 --- a/main.go +++ b/main.go @@ -32,6 +32,7 @@ type Flags struct { Password string `docopt:"-p"` TargetURL string `docopt:"-l"` BaseURL string `docopt:"--base-url"` + Config string `docopt:"--config"` } const ( @@ -55,7 +56,8 @@ Options: above). -b --base-url Base URL for Confluence. Alternative option for base_url config field. - -f Use specified markdown file(s) for converting to html. Supports file globbing patterns (needs to be quoted). + -f Use specified markdown file(s) for converting to html. + Supports file globbing patterns (needs to be quoted). -k Lock page editing to current user only to prevent accidental manual edits over Confluence Web UI. --drop-h1 Don't include H1 headings in Confluence output. @@ -66,13 +68,15 @@ Options: --trace Enable trace logs. --color Display logs in color. Possible values: auto, never. [default: auto] - -h --help Show this screen and call 911. + -c --config Use the specified configuration file. + [default: $HOME/.config/mark] + -h --help Show this message. -v --version Show version. ` ) func main() { - cmd, err := docopt.ParseArgs(usage, nil, version) + cmd, err := docopt.ParseArgs(os.ExpandEnv(usage), nil, version) if err != nil { panic(err) } @@ -100,7 +104,7 @@ func main() { log.GetLogger().SetOutput(os.Stderr) } - config, err := LoadConfig(filepath.Join(os.Getenv("HOME"), ".config/mark")) + config, err := LoadConfig(flags.Config) if err != nil { log.Fatal(err) }