Skip to content

Commit def02fa

Browse files
authored
Merge pull request #3167 from Saurabh825/qpdf
Add qpdf completer
2 parents cd7e97d + 266e607 commit def02fa

File tree

2 files changed

+275
-0
lines changed

2 files changed

+275
-0
lines changed
Lines changed: 268 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,268 @@
1+
package cmd
2+
3+
import (
4+
"github.com/carapace-sh/carapace"
5+
"github.com/carapace-sh/carapace/pkg/style"
6+
"github.com/spf13/cobra"
7+
"github.com/spf13/pflag"
8+
)
9+
10+
var rootCmd = &cobra.Command{
11+
Use: "qpdf",
12+
Short: "PDF transformation software",
13+
Long: "https://qpdf.readthedocs.io/",
14+
Run: func(cmd *cobra.Command, args []string) {},
15+
}
16+
17+
func Execute() error {
18+
return rootCmd.Execute()
19+
}
20+
21+
func init() {
22+
carapace.Gen(rootCmd).Standalone()
23+
24+
rootCmd.Flags().String("accessibility", "", "restrict document accessibility")
25+
rootCmd.Flags().StringSlice("add-attachment", nil, "start add attachment options")
26+
rootCmd.Flags().Bool("allow-insecure", false, "allow empty owner passwords")
27+
rootCmd.Flags().Bool("allow-weak-crypto", false, "allow insecure cryptographic algorithms")
28+
rootCmd.Flags().String("annotate", "", "restrict document annotation")
29+
rootCmd.Flags().String("assemble", "", "restrict document assembly")
30+
rootCmd.Flags().String("bits", "", "specify encryption key length")
31+
rootCmd.Flags().Bool("check", false, "partially check whether PDF is valid")
32+
rootCmd.Flags().Bool("check-linearization", false, "check linearization tables")
33+
rootCmd.Flags().Bool("cleartext-metadata", false, "don't encrypt metadata")
34+
rootCmd.Flags().Bool("coalesce-contents", false, "combine content streams")
35+
rootCmd.Flags().String("collate", "", "collate with --pages")
36+
rootCmd.Flags().Bool("completion-bash", false, "enable bash completion")
37+
rootCmd.Flags().Bool("completion-zsh", false, "enable zsh completion")
38+
rootCmd.Flags().String("compress-streams", "", "compress uncompressed streams")
39+
rootCmd.Flags().String("compression-level", "", "set compression level for flate")
40+
rootCmd.Flags().String("copy-attachments-from", "", "start copy attachment options")
41+
rootCmd.Flags().String("copy-encryption", "", "copy another file's encryption details")
42+
rootCmd.Flags().Bool("copyright", false, "show copyright information")
43+
rootCmd.Flags().StringSlice("creationdate", nil, "set attachment's creation date")
44+
rootCmd.Flags().String("decode-level", "", "control which streams to uncompress")
45+
rootCmd.Flags().Bool("decrypt", false, "remove encryption from input file")
46+
rootCmd.Flags().StringSlice("description", nil, "set attachment's description")
47+
rootCmd.Flags().Bool("deterministic-id", false, "generate ID deterministically")
48+
rootCmd.Flags().Bool("empty", false, "use empty file as input")
49+
rootCmd.Flags().Bool("encrypt", false, "start encryption options")
50+
rootCmd.Flags().String("encryption-file-password", "", "supply password for --copy-encryption")
51+
rootCmd.Flags().Bool("externalize-inline-images", false, "convert inline to regular images")
52+
rootCmd.Flags().String("extract", "", "restrict text/graphic extraction")
53+
rootCmd.Flags().String("file", "", "source for pages")
54+
rootCmd.Flags().StringSlice("filename", nil, "set attachment's displayed filename")
55+
rootCmd.Flags().Bool("filtered-stream-data", false, "show filtered stream data")
56+
rootCmd.Flags().String("flatten-annotations", "", "push annotations into content")
57+
rootCmd.Flags().Bool("flatten-rotation", false, "remove rotation from page dictionary")
58+
rootCmd.Flags().Bool("force-R5", false, "forces use of deprecated R=5 encryption")
59+
rootCmd.Flags().Bool("force-V4", false, "forces use of V=4 encryption handler")
60+
rootCmd.Flags().Bool("force-version", false, "set output PDF version")
61+
rootCmd.Flags().String("form", "", "restrict form filling")
62+
rootCmd.Flags().String("from", "", "source pages for underlay/overlay")
63+
rootCmd.Flags().Bool("generate-appearances", false, "generate appearances for form fields")
64+
rootCmd.Flags().String("help", "", "provide help")
65+
rootCmd.Flags().Bool("ignore-xref-streams", false, "use xref tables rather than streams")
66+
rootCmd.Flags().String("ii-min-bytes", "", "set minimum size for --externalize-inline-images")
67+
rootCmd.Flags().Bool("is-encrypted", false, "silently test whether a file is encrypted")
68+
rootCmd.Flags().String("job-json-file", "", "job JSON file")
69+
rootCmd.Flags().Bool("job-json-help", false, "show format of job JSON")
70+
rootCmd.Flags().String("jpeg-quality", "", "set jpeg quality level for jpeg")
71+
rootCmd.Flags().String("json", "", "show file in JSON format")
72+
rootCmd.Flags().String("json-help", "", "show format of JSON output")
73+
rootCmd.Flags().Bool("json-input", false, "input file is qpdf JSON")
74+
rootCmd.Flags().StringSlice("json-key", nil, "limit which keys are in JSON output")
75+
rootCmd.Flags().StringSlice("json-object", nil, "limit which objects are in JSON")
76+
rootCmd.Flags().String("json-output", "", "apply defaults for JSON serialization")
77+
rootCmd.Flags().String("json-stream-data", "", "how to handle streams in json output")
78+
rootCmd.Flags().String("json-stream-prefix", "", "prefix for json stream data files")
79+
rootCmd.Flags().String("keep-files-open", "", "manage keeping multiple files open")
80+
rootCmd.Flags().String("keep-files-open-threshold", "", "set threshold for --keep-files-open")
81+
rootCmd.Flags().Bool("keep-inline-images", false, "exclude inline images from optimization")
82+
rootCmd.Flags().StringSlice("key", nil, "specify attachment key")
83+
rootCmd.Flags().Bool("linearize", false, "linearize (web-optimize) output")
84+
rootCmd.Flags().String("linearize-pass1", "", "save pass 1 of linearization")
85+
rootCmd.Flags().Bool("list-attachments", false, "list embedded files")
86+
rootCmd.Flags().StringSlice("mimetype", nil, "attachment mime type, e.g. application/pdf")
87+
rootCmd.Flags().String("min-version", "", "set minimum PDF version")
88+
rootCmd.Flags().StringSlice("moddate", nil, "set attachment's modification date")
89+
rootCmd.Flags().String("modify", "", "restrict document modification")
90+
rootCmd.Flags().String("modify-other", "", "restrict other modifications")
91+
rootCmd.Flags().Bool("newline-before-endstream", false, "force a newline before endstream")
92+
rootCmd.Flags().Bool("no-original-object-ids", false, "omit original object IDs in qdf")
93+
rootCmd.Flags().Bool("no-warn", false, "suppress printing of warning messages")
94+
rootCmd.Flags().String("normalize-content", "", "fix newlines in content streams")
95+
rootCmd.Flags().String("object-streams", "", "control use of object streams")
96+
rootCmd.Flags().String("oi-min-area", "", "minimum area for --optimize-images")
97+
rootCmd.Flags().String("oi-min-height", "", "minimum height for --optimize-images")
98+
rootCmd.Flags().String("oi-min-width", "", "minimum width for --optimize-images")
99+
rootCmd.Flags().Bool("optimize-images", false, "use efficient compression for images")
100+
rootCmd.Flags().String("overlay", "", "begin overlay options")
101+
rootCmd.Flags().String("owner-password", "", "specify owner password")
102+
rootCmd.Flags().Bool("pages", false, "show number of pages")
103+
rootCmd.Flags().String("password", "", "silently test a file's password")
104+
rootCmd.Flags().String("password-file", "", "read password from a file")
105+
rootCmd.Flags().Bool("password-is-hex-key", false, "provide hex-encoded encryption key")
106+
rootCmd.Flags().String("password-mode", "", "tweak how qpdf encodes passwords")
107+
rootCmd.Flags().String("prefix", "", "key prefix for copying attachments")
108+
rootCmd.Flags().Bool("preserve-unreferenced", false, "preserve unreferenced objects")
109+
rootCmd.Flags().Bool("preserve-unreferenced-resources", false, "use --remove-unreferenced-resources=no")
110+
rootCmd.Flags().String("print", "", "restrict printing")
111+
rootCmd.Flags().Bool("progress", false, "show progress when writing")
112+
rootCmd.Flags().Bool("qdf", false, "enable viewing PDF code in a text editor")
113+
rootCmd.Flags().String("range", "", "page range")
114+
rootCmd.Flags().Bool("raw-stream-data", false, "show raw stream data")
115+
rootCmd.Flags().Bool("recompress-flate", false, "uncompress and recompress flate")
116+
rootCmd.Flags().String("remove-attachment", "", "remove an embedded file")
117+
rootCmd.Flags().Bool("remove-info", false, "remove file information")
118+
rootCmd.Flags().Bool("remove-metadata", false, "remove metadata")
119+
rootCmd.Flags().Bool("remove-page-labels", false, "remove explicit page numbers")
120+
rootCmd.Flags().Bool("remove-restrictions", false, "remove security restrictions from input file")
121+
rootCmd.Flags().Bool("remove-structure", false, "remove metadata")
122+
rootCmd.Flags().Bool("remove-unreferenced-resources", false, "remove unreferenced page resources")
123+
rootCmd.Flags().String("repeat", "", "overlay/underlay pages to repeat")
124+
rootCmd.Flags().Count("replace", "replace attachment with same key")
125+
rootCmd.Flags().Bool("replace-input", false, "overwrite input with output")
126+
rootCmd.Flags().Bool("report-memory-usage", false, "best effort report of memory usage")
127+
rootCmd.Flags().Bool("requires-password", false, "silently test a file's password")
128+
rootCmd.Flags().String("rotate", "", "rotate pages")
129+
rootCmd.Flags().String("set-page-labels", "", "number pages for the entire document")
130+
rootCmd.Flags().String("show-attachment", "", "export an embedded file")
131+
rootCmd.Flags().Bool("show-crypto", false, "show available crypto providers")
132+
rootCmd.Flags().Bool("show-encryption", false, "information about encrypted files")
133+
rootCmd.Flags().Bool("show-encryption-key", false, "show key with --show-encryption")
134+
rootCmd.Flags().Bool("show-linearization", false, "show linearization hint tables")
135+
rootCmd.Flags().Bool("show-npages", false, "show number of pages")
136+
rootCmd.Flags().String("show-object", "", "show contents of an object")
137+
rootCmd.Flags().Bool("show-pages", false, "display page dictionary information")
138+
rootCmd.Flags().Bool("show-xref", false, "show cross reference data")
139+
rootCmd.Flags().String("split-pages", "", "write pages to separate files")
140+
rootCmd.Flags().Bool("static-aes-iv", false, "use a fixed AES vector")
141+
rootCmd.Flags().Bool("static-id", false, "use a fixed document ID")
142+
rootCmd.Flags().String("stream-data", "", "show filtered stream data")
143+
rootCmd.Flags().Bool("suppress-password-recovery", false, "don't try different password encodings")
144+
rootCmd.Flags().Bool("suppress-recovery", false, "suppress error recovery")
145+
rootCmd.Flags().Bool("test-json-schema", false, "test generated json against schema")
146+
rootCmd.Flags().String("to", "", "destination pages for underlay/overlay")
147+
rootCmd.Flags().Bool("underlay", false, "begin underlay options")
148+
rootCmd.Flags().String("update-from-json", "", "update a PDF from qpdf JSON")
149+
rootCmd.Flags().String("use-aes", "", "use AES with 128-bit encryption")
150+
rootCmd.Flags().String("user-password", "", "specify user password")
151+
rootCmd.Flags().Bool("verbose", false, "print additional information")
152+
rootCmd.Flags().Bool("version", false, "show qpdf version")
153+
rootCmd.Flags().Bool("warning-exit-0", false, "exit 0 even with warnings")
154+
rootCmd.Flags().Bool("with-images", false, "include image details with --show-pages")
155+
rootCmd.Flags().Bool("zopfli", false, "indicate whether zopfli is enabled and active")
156+
157+
rootCmd.Flag("accessibility").NoOptDefVal = " "
158+
rootCmd.Flag("annotate").NoOptDefVal = " "
159+
rootCmd.Flag("assemble").NoOptDefVal = " "
160+
rootCmd.Flag("collate").NoOptDefVal = " "
161+
rootCmd.Flag("compress-streams").NoOptDefVal = " "
162+
rootCmd.Flag("extract").NoOptDefVal = " "
163+
rootCmd.Flag("form").NoOptDefVal = " "
164+
rootCmd.Flag("from").NoOptDefVal = " "
165+
rootCmd.Flag("help").NoOptDefVal = " "
166+
rootCmd.Flag("json").NoOptDefVal = " "
167+
rootCmd.Flag("json-help").NoOptDefVal = " "
168+
rootCmd.Flag("json-output").NoOptDefVal = " "
169+
rootCmd.Flag("keep-files-open").NoOptDefVal = " "
170+
rootCmd.Flag("modify-other").NoOptDefVal = " "
171+
rootCmd.Flag("normalize-content").NoOptDefVal = " "
172+
rootCmd.Flag("split-pages").NoOptDefVal = " "
173+
rootCmd.Flag("use-aes").NoOptDefVal = " "
174+
175+
carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{
176+
"accessibility": carapace.ActionValues("y", "n"),
177+
"add-attachment": carapace.ActionFiles(),
178+
"annotate": carapace.ActionValues("y", "n"),
179+
"assemble": carapace.ActionValues("y", "n"),
180+
"bits": carapace.ActionValues("48", "128", "256"),
181+
"compress-streams": carapace.ActionValues("y", "n"),
182+
"copy-attachments-from": carapace.ActionFiles(),
183+
"copy-encryption": carapace.ActionFiles(),
184+
"extract": carapace.ActionValues("y", "n"),
185+
"file": carapace.ActionFiles(),
186+
"flatten-annotations": carapace.ActionValuesDescribed(
187+
"all", "include all annotations that are not marked invisible or hidden",
188+
"print", "only include annotations that should appear when the page is printed",
189+
"screen", "omit annotations that should not appear on the screen",
190+
),
191+
"form": carapace.ActionValues("y", "n"),
192+
"help": carapace.Batch(
193+
carapace.ActionValuesDescribed(
194+
195+
"all", "all available help",
196+
"add-attachment", "attach (embed) files",
197+
"advanced-control", "tweak qpdf's behavior",
198+
"attachments", "work with embedded files",
199+
"completion", "shell completion",
200+
"copy-attachments", "copy attachments from another file",
201+
"encryption", "create encrypted files",
202+
"exit-status", "meanings of qpdf's exit codes",
203+
"general", "general options",
204+
"help", "information about qpdf",
205+
"inspection", "inspect PDF files",
206+
"json", "JSON output for PDF information",
207+
"modification", "change parts of the PDF",
208+
"overlay-underlay", "overlay/underlay pages from other PDF files",
209+
"page-ranges", "page range syntax",
210+
"page-selection", "select pages from one or more files",
211+
"pdf-dates", "PDF date format",
212+
"testing", "options for testing or debugging",
213+
"transformation", "make structural PDF changes",
214+
"usage", "basic invocation",
215+
),
216+
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
217+
values := []string{}
218+
219+
rootCmd.Flags().VisitAll(func(f *pflag.Flag) {
220+
values = append(values, "--"+f.Name, f.Usage)
221+
})
222+
223+
return carapace.ActionValuesDescribed(values...)
224+
}),
225+
).ToA(),
226+
"job-json-file": carapace.ActionFiles(),
227+
"json-stream-data": carapace.ActionValues("none", "inline", "file"),
228+
"keep-files-open": carapace.ActionValues("y", "n"),
229+
"linearize-pass1": carapace.ActionFiles(),
230+
"modify": carapace.ActionValuesDescribed(
231+
"all", "allow full document modification",
232+
"annotate", "form permissions plus commenting and modifying forms",
233+
"assembly", "allow document assembly only",
234+
"form", "assembly permissions plus filling in form fields and signing",
235+
"none", "allow no modifications",
236+
),
237+
"modify-other": carapace.ActionValues("y", "n"),
238+
"normalize-content": carapace.ActionValues("y", "n"),
239+
"object-streams": carapace.ActionValuesDescribed(
240+
"preserve", "preserve original object streams, if any",
241+
"disable", "create output files with no object streams",
242+
"generate", "create object streams, and compress objects when possible",
243+
),
244+
"overlay": carapace.ActionFiles(),
245+
"pages": carapace.ActionFiles(),
246+
"password-file": carapace.ActionFiles(),
247+
"password-mode": carapace.ActionValues("auto", "unicode", "bytes", "hex-bytes"),
248+
"print": carapace.ActionValuesDescribed(
249+
"none", "disallow printing",
250+
"low", "allow low-resolution printing only",
251+
"full", "allow full printing",
252+
),
253+
"remove-unreferenced-resources": carapace.ActionValues("auto", "yes", "no").StyleF(style.ForKeyword),
254+
"stream-data": carapace.ActionValuesDescribed(
255+
"compress", "recompress stream data when possible",
256+
"preserve", "leave all stream data as is",
257+
"uncompress", "uncompress stream data compressed with generalized filters when possible",
258+
),
259+
"underlay": carapace.ActionFiles(),
260+
"update-from-json": carapace.ActionFiles(),
261+
"use-aes": carapace.ActionValues("y", "n"),
262+
})
263+
264+
carapace.Gen(rootCmd).PositionalCompletion(
265+
carapace.ActionFiles(),
266+
carapace.ActionFiles(),
267+
)
268+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package main
2+
3+
import "github.com/carapace-sh/carapace-bin/completers/common/qpdf_completer/cmd"
4+
5+
func main() {
6+
cmd.Execute()
7+
}

0 commit comments

Comments
 (0)