Debian Codegraph @

src/cli/download.rs

raw
1 //! Command-line parser for `sq download`.
2
3 use clap::{ArgGroup, Parser};
4
5 use crate::cli::examples;
6 use examples::Action;
7 use examples::Actions;
8
9 use super::types::ClapData;
10 use super::types::cert_designator::*;
11 use crate::cli::types::FileOrStdout;
12
13 const EXAMPLES: Actions = Actions {
14 actions: &[
15 Action::setup().command(&[
16 "sq", "cert", "import", "debian/debian-cd-signing-key.pgp",
17 ]).build(),
18
19 Action::example().comment(
20 "Download and verify the Debian 12 checksum file.",
21 ).command(&[
22 "sq", "download",
23 "--url=file://debian/SHA512SUMS",
24 "--signature-url=file://debian/SHA512SUMS.sign",
25 "--signer=DF9B9C49EAA9298432589D76DA87E80D6294BE9B",
26 "--output=SHA512SUMS",
27 ]).build(),
28 ],
29 };
30 test_examples!(sq_download, EXAMPLES);
31
32 #[derive(Parser, Debug)]
33 #[clap(
34 name = "download",
35 about = "Download and authenticate the data",
36 long_about =
37 "Download and authenticate the data
38
39 This command downloads the data from the specified URL, checks the
40 signature, and then authenticates the signer. If the signer cannot be
41 authenticated, the data is deleted, if possible.
42 ",
43 after_help = EXAMPLES,
44 )]
45 #[clap(group(ArgGroup::new("kind")
46 .args(&["detached", "message", "cleartext"]).required(true)))]
47 pub struct Command {
48 #[clap(
49 long = "url",
50 value_name = "URL",
51 help = "The data to download",
52 )]
53 pub url: String,
54
55 #[clap(
56 long = "signature-url",
57 value_name = "URL",
58 help = "URL of the signature",
59 long_help = "\
60 URL of the signature
61
62 Use this when the signature is detached from the data.
63
64 If no signature is specified, then the signature is assumed to be \
65 inline.
66 ",
67 )]
68 pub detached: Option<String>,
69
70 #[clap(
71 long = "message",
72 value_name = "SIG",
73 help = "Verify an inline signed message"
74 )]
75 pub message: bool,
76
77 #[clap(
78 long = "cleartext",
79 value_name = "SIG",
80 help = "Verify a cleartext-signed message"
81 )]
82 pub cleartext: bool,
83
84 #[command(flatten)]
85 pub signers: CertDesignators<FileCertUserIDEmailDomainArgs,
86 SignerPrefix,
87 OptionalValue,
88 ToVerifyDoc>,
89
90 #[clap(
91 long = "signatures",
92 value_name = "N",
93 default_value_t = 1,
94 help = "Set the threshold of valid signatures to N",
95 long_help = "Set the threshold of valid signatures to N
96
97 If this threshold is not reached, the message \
98 will not be considered verified.",
99 )]
100 pub signatures: usize,
101
102 #[clap(
103 help = FileOrStdout::HELP_REQUIRED,
104 long,
105 value_name = FileOrStdout::VALUE_NAME,
106 )]
107 pub output: FileOrStdout,
108 }