Debian Codegraph @

src/bin/ppa-info.rs

raw symbols SCIP
1 //! A simple tool to query PPA information from Launchpad.
2
3 use apt_sourcesrust-analyzer cargo apt-sources 0.3.0 crate/::launchpadrust-analyzer cargo apt-sources 0.3.0 launchpad/::{selfrust-analyzer cargo apt-sources 0.3.0 launchpad/, Errorrust-analyzer cargo apt-sources 0.3.0 launchpad/Error#, PpaInforust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#, PpaSigningKeyrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaSigningKey#, PpaValidationResultrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaValidationResult#};
4 use claprust-analyzer cargo clap 4.6.1 crate/::{Parserrust-analyzer cargo clap_builder 4.6.0 derive/Parser#, Subcommandrust-analyzer cargo clap_builder 4.6.0 derive/Subcommand#};
5 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::processrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/::ExitCoderust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/ExitCode#;
6
7 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Parserrust-analyzer cargo clap_derive 4.6.1 Parser:)]
8 #[command(name = "ppa-info")]
9 #[command(aboutrust-analyzer cargo clap_builder 4.6.0 builder/command/impl#[Command]about(). = "Query PPA information from Launchpad")]
10 #[command(versionrust-analyzer cargo clap_builder 4.6.0 builder/command/impl#[Command]version().)]
11 struct Clirust-analyzer cargo apt-sources 0.3.0 Cli# {
12 /// Enable verbose output
13 #[argrust-analyzer cargo clap_derive 4.6.1 arg:(shortrust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]short()., longrust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]long().)]
14 verboserust-analyzer cargo apt-sources 0.3.0 Cli#verbose.: bool,
15
16 /// Require authentication (for private PPAs)
17 #[argrust-analyzer cargo clap_derive 4.6.1 arg:(shortrust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]short()., longrust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]long().)]
18 loginrust-analyzer cargo apt-sources 0.3.0 Cli#login.: bool,
19
20 #[commandrust-analyzer cargo clap_derive 4.6.1 command:(subcommand)]
21 commandrust-analyzer cargo apt-sources 0.3.0 Cli#command.: Commandsrust-analyzer cargo apt-sources 0.3.0 Commands#,
22 }
23
24 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Subcommandrust-analyzer cargo clap_derive 4.6.1 Subcommand:)]
25 enum Commandsrust-analyzer cargo apt-sources 0.3.0 Commands# {
26 /// Show information about a PPA
27 Inforust-analyzer cargo apt-sources 0.3.0 Commands#Info# {
28 /// PPA specification (e.g., "ppa:user/name" or "user/name")
29 pparust-analyzer cargo apt-sources 0.3.0 Commands#Info#ppa.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
30 },
31 /// Get the signing key for a PPA
32 Keyrust-analyzer cargo apt-sources 0.3.0 Commands#Key# {
33 /// PPA specification (e.g., "ppa:user/name" or "user/name")
34 pparust-analyzer cargo apt-sources 0.3.0 Commands#Key#ppa.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
35
36 /// Output only the key fingerprint
37 #[arg(longrust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]long().)]
38 fingerprint_onlyrust-analyzer cargo apt-sources 0.3.0 Commands#Key#fingerprint_only.: bool,
39 },
40 /// Get the subscription URL for a private PPA
41 SubscriptionUrlrust-analyzer cargo apt-sources 0.3.0 Commands#SubscriptionUrl# {
42 /// PPA specification (e.g., "ppa:user/name" or "user/name")
43 pparust-analyzer cargo apt-sources 0.3.0 Commands#SubscriptionUrl#ppa.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
44 },
45 }
46
47 fn parse_pparust-analyzer cargo apt-sources 0.3.0 parse_ppa().(ppa: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<PpaInforust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
48 PpaInforust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#::parserust-analyzer cargo apt-sources 0.3.0 launchpad/impl#[PpaInfo]parse().(ppa)
49 }
50
51 fn show_inforust-analyzer cargo apt-sources 0.3.0 show_info().(ppa_info: &PpaInforust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#, auth_required: bool) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo apt-sources 0.3.0 launchpad/Error#> {
52 let result: PpaValidationResultrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaValidationResult# = launchpadrust-analyzer cargo apt-sources 0.3.0 launchpad/::validate_pparust-analyzer cargo apt-sources 0.3.0 launchpad/validate_ppa().(ppa_info, auth_required)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
53
54 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().result.existsrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaValidationResult#exists. {
55 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("PPA {}/{} does not exist", ppa_info.userrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#user., ppa_info.namerust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#name.);
56 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(());
57 }
58
59 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("PPA: {}/{}", ppa_info.userrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#user., ppa_info.namerust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#name.);
60 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Display Name: {}", result.display_namerust-analyzer cargo apt-sources 0.3.0 launchpad/PpaValidationResult#display_name.);
61 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Private: {}", if result.is_privaterust-analyzer cargo apt-sources 0.3.0 launchpad/PpaValidationResult#is_private. { "yes" } else { "no" });
62 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(
63 "Debug Symbols: {}",
64 if result.publishes_debug_symbolsrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaValidationResult#publishes_debug_symbols. {
65 "yes"
66 } else {
67 "no"
68 }
69 );
70
71 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
72 }
73
74 fn show_keyrust-analyzer cargo apt-sources 0.3.0 show_key().(ppa_info: &PpaInforust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#, auth_required: bool, fingerprint_only: &bool) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo apt-sources 0.3.0 launchpad/Error#> {
75 let signing_key: PpaSigningKeyrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaSigningKey# = launchpadrust-analyzer cargo apt-sources 0.3.0 launchpad/::download_ppa_signing_keyrust-analyzer cargo apt-sources 0.3.0 launchpad/download_ppa_signing_key().(ppa_info, auth_required)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
76
77 if *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().fingerprint_only {
78 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{}", signing_key.fingerprintrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaSigningKey#fingerprint.);
79 } else {
80 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Fingerprint: {}", signing_key.fingerprintrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaSigningKey#fingerprint.);
81 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!();
82 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{}", signing_key.key_datarust-analyzer cargo apt-sources 0.3.0 launchpad/PpaSigningKey#key_data.);
83 }
84
85 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
86 }
87
88 fn show_subscription_urlrust-analyzer cargo apt-sources 0.3.0 show_subscription_url().(ppa_info: &PpaInforust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo apt-sources 0.3.0 launchpad/Error#> {
89 let url = launchpadrust-analyzer cargo apt-sources 0.3.0 launchpad/::get_private_ppa_urlrust-analyzer cargo apt-sources 0.3.0 launchpad/get_private_ppa_url().(ppa_info)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
90 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{}", url);
91 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
92 }
93
94 fn mainrust-analyzer cargo apt-sources 0.3.0 main().() -> ExitCoderust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/ExitCode# {
95 let cli = Clirust-analyzer cargo apt-sources 0.3.0 Cli#::parserust-analyzer cargo clap_builder 4.6.0 derive/Parser#parse().();
96
97 if cli.verboserust-analyzer cargo apt-sources 0.3.0 Cli#verbose. {
98 env_loggerrust-analyzer cargo env_logger 0.11.10 crate/::Builderrust-analyzer cargo env_logger 0.11.10 logger/Builder#::from_envrust-analyzer cargo env_logger 0.11.10 logger/impl#[Builder]from_env().(env_loggerrust-analyzer cargo env_logger 0.11.10 crate/::Envrust-analyzer cargo env_logger 0.11.10 logger/Env#::defaultrust-analyzer cargo env_logger 0.11.10 logger/impl#[`Env<'_>`][Default]default().().default_filter_orrust-analyzer cargo env_logger 0.11.10 logger/impl#[`Env<'a>`]default_filter_or().("debug")).initrust-analyzer cargo env_logger 0.11.10 logger/impl#[Builder]init().();
99 } else {
100 env_loggerrust-analyzer cargo env_logger 0.11.10 crate/::Builderrust-analyzer cargo env_logger 0.11.10 logger/Builder#::from_envrust-analyzer cargo env_logger 0.11.10 logger/impl#[Builder]from_env().(env_loggerrust-analyzer cargo env_logger 0.11.10 crate/::Envrust-analyzer cargo env_logger 0.11.10 logger/Env#::defaultrust-analyzer cargo env_logger 0.11.10 logger/impl#[`Env<'_>`][Default]default().().default_filter_orrust-analyzer cargo env_logger 0.11.10 logger/impl#[`Env<'a>`]default_filter_or().("warn")).initrust-analyzer cargo env_logger 0.11.10 logger/impl#[Builder]init().();
101 }
102
103 let result = match &cli.commandrust-analyzer cargo apt-sources 0.3.0 Cli#command. {
104 Commandsrust-analyzer cargo apt-sources 0.3.0 Commands#::Inforust-analyzer cargo apt-sources 0.3.0 Commands#Info# { pparust-analyzer cargo apt-sources 0.3.0 Commands#Info#ppa. } => {
105 let ppa_info = match parse_pparust-analyzer cargo apt-sources 0.3.0 parse_ppa().(&ppa) {
106 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(info) => info,
107 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
108 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("Error: {}", e);
109 return ExitCoderust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/ExitCode#::FAILURErust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[ExitCode]FAILURE.;
110 }
111 };
112 show_inforust-analyzer cargo apt-sources 0.3.0 show_info().(&ppa_info, cli.loginrust-analyzer cargo apt-sources 0.3.0 Cli#login.)
113 }
114 Commandsrust-analyzer cargo apt-sources 0.3.0 Commands#::Keyrust-analyzer cargo apt-sources 0.3.0 Commands#Key# {
115 pparust-analyzer cargo apt-sources 0.3.0 Commands#Key#ppa.,
116 fingerprint_onlyrust-analyzer cargo apt-sources 0.3.0 Commands#Key#fingerprint_only.,
117 } => {
118 let ppa_info = match parse_pparust-analyzer cargo apt-sources 0.3.0 parse_ppa().(&ppa) {
119 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(info) => info,
120 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
121 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("Error: {}", e);
122 return ExitCoderust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/ExitCode#::FAILURErust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[ExitCode]FAILURE.;
123 }
124 };
125 show_keyrust-analyzer cargo apt-sources 0.3.0 show_key().(&ppa_info, cli.loginrust-analyzer cargo apt-sources 0.3.0 Cli#login., fingerprint_only)
126 }
127 Commandsrust-analyzer cargo apt-sources 0.3.0 Commands#::SubscriptionUrlrust-analyzer cargo apt-sources 0.3.0 Commands#SubscriptionUrl# { pparust-analyzer cargo apt-sources 0.3.0 Commands#SubscriptionUrl#ppa. } => {
128 let ppa_info = match parse_pparust-analyzer cargo apt-sources 0.3.0 parse_ppa().(&ppa) {
129 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(info) => info,
130 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
131 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("Error: {}", e);
132 return ExitCoderust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/ExitCode#::FAILURErust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[ExitCode]FAILURE.;
133 }
134 };
135 show_subscription_urlrust-analyzer cargo apt-sources 0.3.0 show_subscription_url().(&ppa_info)
136 }
137 };
138
139 match result {
140 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) => ExitCoderust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/ExitCode#::SUCCESSrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[ExitCode]SUCCESS.,
141 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
142 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("Error: {}", e);
143 ExitCoderust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/ExitCode#::FAILURErust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[ExitCode]FAILURE.
144 }
145 }
146 }