diff --git a/main.go b/main.go index 621ea74..f1c166a 100644 --- a/main.go +++ b/main.go @@ -37,8 +37,8 @@ usable for git hooks. That file should have following format: file = "docs/README.md" Usage: - mark [-u ] [-p ] -l -f - mark [-u ] [-p ] -c + mark [--dry-run] [-u ] [-p ] -l -f + mark [--dry-run] [-u ] [-p ] -c mark -v | --version mark -h | --help @@ -49,6 +49,7 @@ Options: -f Use specified markdown file for converting to html. -c Specify configuration file which should be used for reading Confluence page URL and markdown file path. + --dry-run Show resulting HTML and don't update Confluence page content. -h --help Show this screen and call 911. -v --version Show version. ` @@ -72,10 +73,23 @@ func main() { password, _ = args["-p"].(string) targetURL, _ = args["-l"].(string) targetFile, _ = args["-f"].(string) + dryRun = args["--dry-run"].(bool) optionsFile, shouldReadOptions = args["-c"].(string) ) + markdownData, err := ioutil.ReadFile(targetFile) + if err != nil { + log.Fatal(err) + } + + htmlData := blackfriday.MarkdownCommon(markdownData) + + if dryRun { + fmt.Println(string(htmlData)) + os.Exit(0) + } + config, err := getConfig(filepath.Join(os.Getenv("HOME"), ".config/mark")) if err != nil && !os.IsNotExist(err) { log.Fatal(err) @@ -132,13 +146,6 @@ func main() { } } - markdownData, err := ioutil.ReadFile(targetFile) - if err != nil { - log.Fatal(err) - } - - htmlData := blackfriday.MarkdownCommon(markdownData) - url, err := url.Parse(targetURL) if err != nil { log.Fatal(err) @@ -197,9 +204,13 @@ func updatePage( } if request.Raw.StatusCode != 200 { + output, _ := ioutil.ReadAll(request.Raw.Body) + defer request.Raw.Body.Close() + return fmt.Errorf( - "Confluence REST API returns unexpected HTTP status: %s", - request.Raw.Status, + "Confluence REST API returns unexpected HTTP status: %s, "+ + "output: %s", + request.Raw.Status, output, ) }