forked from unidoc/unipdf-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroot.go
More file actions
82 lines (62 loc) · 2.09 KB
/
Copy pathroot.go
File metadata and controls
82 lines (62 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* This file is subject to the terms and conditions defined in
* file 'LICENSE.md', which is part of this source code package.
*/
package cli
import (
"os"
"github.com/spf13/cobra"
"github.com/unidoc/unipdf-cli/pkg/pdf"
unicommon "github.com/unidoc/unipdf/v4/common"
)
const appName = "unipdf"
const appVersion = "0.13.0"
const rootCmdDesc = ` is a CLI application for working with PDF files.
It supports the most common PDF operations. A full list of the supported
operations can be found below.
If you have a license for Unidoc, you can set it through the
UNIDOC_LICENSE_FILE and UNIDOC_LICENSE_CUSTOMER environment variables.
export UNIDOC_LICENSE_FILE="PATH_TO_LICENSE_FILE"
export UNIDOC_LICENSE_CUSTOMER="CUSTOMER_NAME"
Or alternatively, you can set the Metered API Key license through the
UNIDOC_LICENSE_API_KEY environment variable.
export UNIDOC_LICENSE_API_KEY="YOUR_API_KEY_HERE"
By default, the application only displays error messages on command execution
failure. To change the verbosity of the output, set the UNIDOC_LOG_LEVEL
environment variable.
export UNIDOC_LOG_LEVEL="DEBUG"
Supported log levels: trace, debug, info, notice, warning, error (default)
`
var rootCmd = &cobra.Command{
Use: appName,
Long: appName + rootCmdDesc,
}
// Execute represents the entry point of the application.
// The method parses the command line arguments and executes the appropriate
// action.
func Execute() {
readEnv()
if err := rootCmd.Execute(); err != nil {
printErr("%s\n", err)
}
}
func readEnv() {
// Set license key.
licensePath := os.Getenv("UNIDOC_LICENSE_FILE")
licenseCustomer := os.Getenv("UNIDOC_LICENSE_CUSTOMER")
if licensePath != "" {
pdf.SetLicense(licensePath, licenseCustomer)
}
// OR... alternatively... load a License API key.
// Set license key using metered api key.
licenseMeteredKey := os.Getenv("UNIDOC_LICENSE_API_KEY")
if licenseMeteredKey != "" {
pdf.SetMeteredKey(licenseMeteredKey)
}
// Set log level.
logLevel, err := parseLogLevel(os.Getenv("UNIDOC_LOG_LEVEL"))
if err != nil {
logLevel = unicommon.LogLevelError
}
pdf.SetLogLevel(logLevel)
}