@@ -24,6 +24,8 @@ import (
2424 "os"
2525 "path/filepath"
2626 "regexp"
27+ "runtime"
28+ "runtime/debug"
2729 "sort"
2830 "strconv"
2931 "strings"
@@ -123,13 +125,24 @@ func printVersion(conf *model.Configuration) {
123125 os .Exit (1 )
124126 }
125127
126- fmt .Fprintf (os .Stdout , "pdfcpu: %v\n " , model .VersionStr )
127- if date != "?" {
128- fmt .Fprintf (os .Stdout , "build : %v\n commit: %v\n " , date , commit )
129- }
130- if verbose {
131- fmt .Fprintf (os .Stdout , "config: %s\n " , conf .Path )
128+ fmt .Fprintf (os .Stdout , "pdfcpu: %s\n " , model .VersionStr )
129+
130+ if date == "?" {
131+ if info , ok := debug .ReadBuildInfo (); ok {
132+ for _ , setting := range info .Settings {
133+ if setting .Key == "vcs.revision" {
134+ commit = setting .Value
135+ }
136+ if setting .Key == "vcs.time" {
137+ date = setting .Value
138+ }
139+ }
140+ }
132141 }
142+
143+ fmt .Fprintf (os .Stdout , "commit: %s (%s)\n " , commit [:8 ], date )
144+ fmt .Fprintf (os .Stdout , "base : %s\n " , runtime .Version ())
145+ fmt .Fprintf (os .Stdout , "config: %s\n " , conf .Path )
133146}
134147
135148func process (cmd * cli.Command ) {
@@ -247,7 +260,7 @@ func processSplitCommand(conf *model.Configuration) {
247260 if mode == "" {
248261 mode = "span"
249262 }
250- mode = extractModeCompletion (mode , []string {"span" , "bookmark" , "page" })
263+ mode = modeCompletion (mode , []string {"span" , "bookmark" , "page" })
251264 if mode == "" || len (flag .Args ()) < 2 || selectedPages != "" {
252265 fmt .Fprintf (os .Stderr , "%s\n \n " , usageSplit )
253266 os .Exit (1 )
@@ -302,21 +315,7 @@ func sortFiles(filesIn []string) {
302315 })
303316}
304317
305- func processMergeCommand (conf * model.Configuration ) {
306- if mode == "" {
307- mode = "create"
308- }
309- mode = extractModeCompletion (mode , []string {"create" , "append" })
310- if mode == "" {
311- fmt .Fprintf (os .Stderr , "%s\n \n " , usageMerge )
312- os .Exit (1 )
313- }
314-
315- if len (flag .Args ()) < 2 || selectedPages != "" {
316- fmt .Fprintf (os .Stderr , "%s\n \n " , usageMerge )
317- os .Exit (1 )
318- }
319-
318+ func processArgsForMerge (conf * model.Configuration ) ([]string , string ) {
320319 filesIn := []string {}
321320 outFile := ""
322321 for i , arg := range flag .Args () {
@@ -329,7 +328,7 @@ func processMergeCommand(conf *model.Configuration) {
329328 fmt .Fprintf (os .Stderr , "%s may appear as inFile or outFile only\n " , outFile )
330329 os .Exit (1 )
331330 }
332- if strings .Contains (arg , "*" ) {
331+ if mode != "zip" && strings .Contains (arg , "*" ) {
333332 matches , err := filepath .Glob (arg )
334333 if err != nil {
335334 fmt .Fprintf (os .Stderr , "%s" , err )
@@ -343,6 +342,34 @@ func processMergeCommand(conf *model.Configuration) {
343342 }
344343 filesIn = append (filesIn , arg )
345344 }
345+ return filesIn , outFile
346+ }
347+
348+ func processMergeCommand (conf * model.Configuration ) {
349+ if mode == "" {
350+ mode = "create"
351+ }
352+ mode = modeCompletion (mode , []string {"create" , "append" , "zip" })
353+ if mode == "" {
354+ fmt .Fprintf (os .Stderr , "%s\n \n " , usageMerge )
355+ os .Exit (1 )
356+ }
357+
358+ if len (flag .Args ()) < 2 || selectedPages != "" {
359+ fmt .Fprintf (os .Stderr , "%s\n \n " , usageMerge )
360+ os .Exit (1 )
361+ }
362+
363+ if mode == "zip" && len (flag .Args ()) != 3 {
364+ fmt .Fprintf (os .Stderr , "merge zip: expecting outFile inFile1 inFile2\n " )
365+ os .Exit (1 )
366+ }
367+
368+ if mode == "zip" && dividerPage {
369+ fmt .Fprintf (os .Stderr , "merge zip: -d(ivider) not applicable and will be ignored\n " )
370+ }
371+
372+ filesIn , outFile := processArgsForMerge (conf )
346373
347374 if sorted {
348375 sortFiles (filesIn )
@@ -360,16 +387,20 @@ func processMergeCommand(conf *model.Configuration) {
360387 switch mode {
361388
362389 case "create" :
363- cmd = cli .MergeCreateCommand (filesIn , outFile , conf )
390+ cmd = cli .MergeCreateCommand (filesIn , outFile , dividerPage , conf )
391+
392+ case "zip" :
393+ cmd = cli .MergeCreateZipCommand (filesIn , outFile , conf )
364394
365395 case "append" :
366- cmd = cli .MergeAppendCommand (filesIn , outFile , conf )
396+ cmd = cli .MergeAppendCommand (filesIn , outFile , dividerPage , conf )
397+
367398 }
368399
369400 process (cmd )
370401}
371402
372- func extractModeCompletion (modePrefix string , modes []string ) string {
403+ func modeCompletion (modePrefix string , modes []string ) string {
373404 var modeStr string
374405 for _ , mode := range modes {
375406 if ! strings .HasPrefix (mode , modePrefix ) {
@@ -384,7 +415,7 @@ func extractModeCompletion(modePrefix string, modes []string) string {
384415}
385416
386417func processExtractCommand (conf * model.Configuration ) {
387- mode = extractModeCompletion (mode , []string {"image" , "font" , "page" , "content" , "meta" })
418+ mode = modeCompletion (mode , []string {"image" , "font" , "page" , "content" , "meta" })
388419 if len (flag .Args ()) != 2 || mode == "" {
389420 fmt .Fprintf (os .Stderr , "%s\n \n " , usageExtract )
390421 os .Exit (1 )
@@ -2061,7 +2092,7 @@ func processMultiFillFormCommand(conf *model.Configuration) {
20612092 if mode == "" {
20622093 mode = "single"
20632094 }
2064- mode = extractModeCompletion (mode , []string {"single" , "merge" })
2095+ mode = modeCompletion (mode , []string {"single" , "merge" })
20652096 if mode == "" {
20662097 fmt .Fprintf (os .Stderr , "usage: %s\n \n " , usageFormMultiFill )
20672098 os .Exit (1 )
0 commit comments