Skip to content

Commit

Permalink
add dry run mode
Browse files Browse the repository at this point in the history
  • Loading branch information
kovetskiy committed Sep 19, 2015
1 parent b60aaa5 commit bf19b91
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ usable for git hooks. That file should have following format:
file = "docs/README.md"
Usage:
mark [-u <username>] [-p <password>] -l <url> -f <file>
mark [-u <username>] [-p <password>] -c <file>
mark [--dry-run] [-u <username>] [-p <password>] -l <url> -f <file>
mark [--dry-run] [-u <username>] [-p <password>] -c <file>
mark -v | --version
mark -h | --help
Expand All @@ -49,6 +49,7 @@ Options:
-f <file> Use specified markdown file for converting to html.
-c <file> 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.
`
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
)
}

Expand Down

0 comments on commit bf19b91

Please sign in to comment.