package main import ( "log" "os" "pdf/lib" "github.com/urfave/cli/v2" ) func main() { app := &cli.App{ Name: "pdf_invoice", Usage: "Pdf xml invoice helper cli", UseShortOptionHandling: true, Commands: []*cli.Command{ { Name: "extract", UseShortOptionHandling: true, Usage: " [] Extract xml invoice from pdf", Flags: []cli.Flag{ &cli.BoolFlag{ Name: "debug", Usage: "Debug flag", Aliases: []string{"d"}, }, }, Action: func(context *cli.Context) error { inputFilePath := context.Args().Get(0) outputFilePath := context.Args().Get(1) debug := context.Bool("debug") lib.EnableDebug(debug) lib.ExtractFromPdf(inputFilePath, outputFilePath) return nil }, }, { Name: "append", Usage: " Append xml invoice to pdf", UseShortOptionHandling: true, Flags: []cli.Flag{ &cli.StringFlag{ Name: "xml-input", Value: "", Usage: "Optional path to xml input File", Required: false, }, &cli.StringFlag{ Name: "out", Usage: "Optional path to pdf output File", Aliases: []string{"o"}, }, &cli.BoolFlag{ Name: "debug", Usage: "Debug flag", Aliases: []string{"d"}, }, &cli.StringFlag{ Name: "description", Usage: "Description for the embedded xml file", Required: false, }, &cli.StringFlag{ Name: "embedded-name", Usage: "Name of the xml file inside the pdf", Required: false, }, }, Action: func(context *cli.Context) error { inputPdfFilePath := context.Args().Get(0) inputXmlFilePath := context.String("xml-input") outputFilePath := context.String("out") description := context.String("description") embedName := context.String("embedded-name") debug := context.Bool("debug") lib.EnableDebug(debug) lib.AppendToPdf(inputPdfFilePath, inputXmlFilePath, outputFilePath, embedName, description) return nil }, }, }, } var err error err = app.Run(os.Args) if err != nil { log.Fatal(err) } }