102 lines
2.3 KiB
Go
Executable File
102 lines
2.3 KiB
Go
Executable File
package main
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
"path"
|
|
|
|
"pdf/lib"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
func main() {
|
|
exeName, err := os.Executable()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
app := &cli.App{
|
|
Name: path.Base(exeName),
|
|
Usage: "Pdf xml invoice helper cli",
|
|
UseShortOptionHandling: true,
|
|
Version: "1.0.1",
|
|
Commands: []*cli.Command{
|
|
{
|
|
Name: "extract",
|
|
UseShortOptionHandling: true,
|
|
Usage: "<input-pdf> [<output-file>] 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: "<input-pdf> 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
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
err = app.Run(os.Args)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|