@@ -18,18 +18,25 @@ import (
1818 "github.com/reconquest/pkg/log"
1919)
2020
21- type markFlags struct {
22- fileGlobPatten string
23- compileOnly bool
24- dryRun bool
25- editLock bool
26- dropH1 bool
27- minorEdit bool
28- color string
21+ type Flags struct {
22+ FileGlobPatten string `docopt:"-f"`
23+ CompileOnly bool `docopt:"--compile-only"`
24+ DryRun bool `docopt:"--dry-run"`
25+ EditLock bool `docopt:"-k"`
26+ DropH1 bool `docopt:"--drop-h1"`
27+ MinorEdit bool `docopt:"--minor-edit"`
28+ Color string `docopt:"--color"`
29+ Debug bool `docopt:"--debug"`
30+ Trace bool `docopt:"--trace"`
31+ Username string `docopt:"-u"`
32+ Password string `docopt:"-p"`
33+ TargetURL string `docopt:"-l"`
34+ BaseURL string `docopt:"--base-url"`
2935}
3036
3137const (
32- usage = `mark - a tool for updating Atlassian Confluence pages from markdown.
38+ version = "5.6"
39+ usage = `mark - a tool for updating Atlassian Confluence pages from markdown.
3340
3441Docs: https://github.com/kovetskiy/mark
3542
@@ -65,30 +72,26 @@ Options:
6572)
6673
6774func main () {
68- args , err := docopt .ParseArgs (usage , nil , "5.6" )
75+ cmd , err := docopt .ParseArgs (usage , nil , version )
6976 if err != nil {
7077 panic (err )
7178 }
7279
73- flags := & markFlags {
74- fileGlobPatten : args ["-f" ].(string ),
75- compileOnly : args ["--compile-only" ].(bool ),
76- dryRun : args ["--dry-run" ].(bool ),
77- editLock : args ["-k" ].(bool ),
78- dropH1 : args ["--drop-h1" ].(bool ),
79- minorEdit : args ["--minor-edit" ].(bool ),
80- color : args ["--color" ].(string ),
80+ var flags Flags
81+ err = cmd .Bind (& flags )
82+ if err != nil {
83+ log .Fatal (err )
8184 }
8285
83- if args [ "--debug" ].( bool ) {
86+ if flags . Debug {
8487 log .SetLevel (lorg .LevelDebug )
8588 }
8689
87- if args [ "--trace" ].( bool ) {
90+ if flags . Trace {
8891 log .SetLevel (lorg .LevelTrace )
8992 }
9093
91- if flags .color == "never" {
94+ if flags .Color == "never" {
9295 log .GetLogger ().SetFormat (
9396 lorg .NewFormat (
9497 `${time:2006-01-02 15:04:05.000} ${level:%s:left:true} ${prefix}%s` ,
@@ -102,26 +105,26 @@ func main() {
102105 log .Fatal (err )
103106 }
104107
105- creds , err := GetCredentials (args , config )
108+ creds , err := GetCredentials (flags , config )
106109 if err != nil {
107110 log .Fatal (err )
108111 }
109112
110113 api := confluence .NewAPI (creds .BaseURL , creds .Username , creds .Password )
111114
112- files , err := filepath .Glob (flags .fileGlobPatten )
115+ files , err := filepath .Glob (flags .FileGlobPatten )
113116 if err != nil {
114117 log .Fatal (err )
115118 }
116119 if len (files ) == 0 {
117- log .Fatal ("No files matched. " )
120+ log .Fatal ("No files matched" )
118121 }
119122
120123 // Loop through files matched by glob pattern
121124 for _ , file := range files {
122125 log .Infof (
123126 nil ,
124- "Processing %s... " ,
127+ "processing %s" ,
125128 file ,
126129 )
127130
@@ -133,13 +136,17 @@ func main() {
133136 creds .BaseURL + target .Links .Full ,
134137 )
135138
136- fmt .Println (
137- "Page available at:" , creds .BaseURL + target .Links .Full ,
138- )
139+ fmt .Println (creds .BaseURL + target .Links .Full )
139140 }
140141}
141142
142- func processFile (file string , api * confluence.API , flags * markFlags , pageID string , username string ) * confluence.PageInfo {
143+ func processFile (
144+ file string ,
145+ api * confluence.API ,
146+ flags Flags ,
147+ pageID string ,
148+ username string ,
149+ ) * confluence.PageInfo {
143150 markdown , err := ioutil .ReadFile (file )
144151 if err != nil {
145152 log .Fatal (err )
@@ -194,16 +201,16 @@ func processFile(file string, api *confluence.API, flags *markFlags, pageID stri
194201
195202 markdown = mark .SubstituteLinks (markdown , links )
196203
197- if flags .dryRun {
198- flags .compileOnly = true
204+ if flags .DryRun {
205+ flags .CompileOnly = true
199206
200- _ , _ , err := mark .ResolvePage (flags .dryRun , api , meta )
207+ _ , _ , err := mark .ResolvePage (flags .DryRun , api , meta )
201208 if err != nil {
202209 log .Fatalf (err , "unable to resolve page location" )
203210 }
204211 }
205212
206- if flags .compileOnly {
213+ if flags .CompileOnly {
207214 fmt .Println (mark .CompileMarkdown (markdown , stdlib ))
208215 os .Exit (0 )
209216 }
@@ -228,7 +235,7 @@ func processFile(file string, api *confluence.API, flags *markFlags, pageID stri
228235 var target * confluence.PageInfo
229236
230237 if meta != nil {
231- parent , page , err := mark .ResolvePage (flags .dryRun , api , meta )
238+ parent , page , err := mark .ResolvePage (flags .DryRun , api , meta )
232239 if err != nil {
233240 log .Fatalf (
234241 karma .Describe ("title" , meta .Title ).Reason (err ),
@@ -238,7 +245,13 @@ func processFile(file string, api *confluence.API, flags *markFlags, pageID stri
238245 }
239246
240247 if page == nil {
241- page , err = api .CreatePage (meta .Space , meta .Type , parent , meta .Title , `` )
248+ page , err = api .CreatePage (
249+ meta .Space ,
250+ meta .Type ,
251+ parent ,
252+ meta .Title ,
253+ `` ,
254+ )
242255 if err != nil {
243256 log .Fatalf (
244257 err ,
@@ -270,9 +283,9 @@ func processFile(file string, api *confluence.API, flags *markFlags, pageID stri
270283
271284 markdown = mark .CompileAttachmentLinks (markdown , attaches )
272285
273- if flags .dropH1 {
286+ if flags .DropH1 {
274287 log .Info (
275- "Leading H1 heading will be excluded from the Confluence output" ,
288+ "the leading H1 heading will be excluded from the Confluence output" ,
276289 )
277290 markdown = mark .DropDocumentLeadingH1 (markdown )
278291 }
@@ -300,23 +313,20 @@ func processFile(file string, api *confluence.API, flags *markFlags, pageID stri
300313 html = buffer .String ()
301314 }
302315
303- err = api .UpdatePage (target , html , flags .minorEdit , meta .Labels )
316+ err = api .UpdatePage (target , html , flags .MinorEdit , meta .Labels )
304317 if err != nil {
305318 log .Fatal (err )
306319 }
307320
308- if flags .editLock {
321+ if flags .EditLock {
309322 log .Infof (
310323 nil ,
311324 `edit locked on page %q by user %q to prevent manual edits` ,
312325 target .Title ,
313326 username ,
314327 )
315328
316- err := api .RestrictPageUpdates (
317- target ,
318- username ,
319- )
329+ err := api .RestrictPageUpdates (target , username )
320330 if err != nil {
321331 log .Fatal (err )
322332 }
0 commit comments