From 766aba2508f270f152b5fae495bfb8adf64fabf3 Mon Sep 17 00:00:00 2001 From: Egor Kovetskiy Date: Sun, 20 Sep 2015 01:00:17 +0600 Subject: [PATCH] fix dry run with options file --- README.md | 2 +- main.go | 56 +++++++++++++++++++++++++++---------------------------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 8a07d1a..baa5540 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Mark -Mark it's tool for syncing your markdown documentation with Atlassian +Mark it's the tool for syncing your markdown documentation with Atlassian Confluence pages. This is very usable if you store documentation to your orthodox software in git diff --git a/main.go b/main.go index f1c166a..b632165 100644 --- a/main.go +++ b/main.go @@ -78,6 +78,34 @@ func main() { optionsFile, shouldReadOptions = args["-c"].(string) ) + config, err := getConfig(filepath.Join(os.Getenv("HOME"), ".config/mark")) + if err != nil && !os.IsNotExist(err) { + log.Fatal(err) + } + + if shouldReadOptions { + optionsConfig, err := getConfig(optionsFile) + if err != nil { + log.Fatalf("can't read options config '%s': %s", optionsFile, err) + } + + targetURL, err = optionsConfig.GetString("url") + if err != nil { + log.Fatal( + "can't read `url` value from options file (%s): %s", + optionsFile, err, + ) + } + + targetFile, err = optionsConfig.GetString("file") + if err != nil { + log.Fatal( + "can't read `file` value from options file (%s): %s", + optionsFile, err, + ) + } + } + markdownData, err := ioutil.ReadFile(targetFile) if err != nil { log.Fatal(err) @@ -90,11 +118,6 @@ func main() { os.Exit(0) } - config, err := getConfig(filepath.Join(os.Getenv("HOME"), ".config/mark")) - if err != nil && !os.IsNotExist(err) { - log.Fatal(err) - } - if username == "" { username, err = config.GetString("username") if err != nil { @@ -123,29 +146,6 @@ func main() { } } - if shouldReadOptions { - optionsConfig, err := getConfig(optionsFile) - if err != nil { - log.Fatalf("can't read options config '%s': %s", optionsFile, err) - } - - targetURL, err = optionsConfig.GetString("url") - if err != nil { - log.Fatal( - "can't read `url` value from options file (%s): %s", - optionsFile, err, - ) - } - - targetFile, err = optionsConfig.GetString("file") - if err != nil { - log.Fatal( - "can't read `file` value from options file (%s): %s", - optionsFile, err, - ) - } - } - url, err := url.Parse(targetURL) if err != nil { log.Fatal(err)