mirror of
https://github.com/kovetskiy/mark.git
synced 2025-04-24 05:42:40 +08:00
add dry run mode
This commit is contained in:
parent
b60aaa51d5
commit
bf19b9124d
33
main.go
33
main.go
@ -37,8 +37,8 @@ usable for git hooks. That file should have following format:
|
|||||||
file = "docs/README.md"
|
file = "docs/README.md"
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
mark [-u <username>] [-p <password>] -l <url> -f <file>
|
mark [--dry-run] [-u <username>] [-p <password>] -l <url> -f <file>
|
||||||
mark [-u <username>] [-p <password>] -c <file>
|
mark [--dry-run] [-u <username>] [-p <password>] -c <file>
|
||||||
mark -v | --version
|
mark -v | --version
|
||||||
mark -h | --help
|
mark -h | --help
|
||||||
|
|
||||||
@ -49,6 +49,7 @@ Options:
|
|||||||
-f <file> Use specified markdown file for converting to html.
|
-f <file> Use specified markdown file for converting to html.
|
||||||
-c <file> Specify configuration file which should be used for reading
|
-c <file> Specify configuration file which should be used for reading
|
||||||
Confluence page URL and markdown file path.
|
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.
|
-h --help Show this screen and call 911.
|
||||||
-v --version Show version.
|
-v --version Show version.
|
||||||
`
|
`
|
||||||
@ -72,10 +73,23 @@ func main() {
|
|||||||
password, _ = args["-p"].(string)
|
password, _ = args["-p"].(string)
|
||||||
targetURL, _ = args["-l"].(string)
|
targetURL, _ = args["-l"].(string)
|
||||||
targetFile, _ = args["-f"].(string)
|
targetFile, _ = args["-f"].(string)
|
||||||
|
dryRun = args["--dry-run"].(bool)
|
||||||
|
|
||||||
optionsFile, shouldReadOptions = args["-c"].(string)
|
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"))
|
config, err := getConfig(filepath.Join(os.Getenv("HOME"), ".config/mark"))
|
||||||
if err != nil && !os.IsNotExist(err) {
|
if err != nil && !os.IsNotExist(err) {
|
||||||
log.Fatal(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)
|
url, err := url.Parse(targetURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@ -197,9 +204,13 @@ func updatePage(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if request.Raw.StatusCode != 200 {
|
if request.Raw.StatusCode != 200 {
|
||||||
|
output, _ := ioutil.ReadAll(request.Raw.Body)
|
||||||
|
defer request.Raw.Body.Close()
|
||||||
|
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"Confluence REST API returns unexpected HTTP status: %s",
|
"Confluence REST API returns unexpected HTTP status: %s, "+
|
||||||
request.Raw.Status,
|
"output: %s",
|
||||||
|
request.Raw.Status, output,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user