Connect applications to schemes, filetypes, and more on macOS (more to come)
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

added --scheme option for info command

+68 -23
+18 -15
infat-cli/src/cli.rs
··· 36 36 pub(crate) enum Commands { 37 37 /// Show file association information 38 38 Info { 39 - /// Application name to inspect 40 - #[arg(short, long, value_name = "APP")] 39 + /// Show information for a specific application 40 + #[arg(long, conflicts_with_all = ["ext", "scheme", "type"])] 41 41 app: Option<String>, 42 42 43 - /// File extension (without dot) 44 - #[arg(short, long, value_name = "EXT")] 43 + /// Show information for a file extension 44 + #[arg(long, conflicts_with_all = ["app", "scheme", "type"])] 45 45 ext: Option<String>, 46 46 47 - /// File type/supertype 48 - #[arg(short, long, value_name = "TYPE")] 47 + /// Show information for a URL scheme 48 + #[arg(long, conflicts_with_all = ["app", "ext", "type"])] 49 + scheme: Option<String>, 50 + 51 + /// Show information for a file type 52 + #[arg(long, conflicts_with_all = ["app", "ext", "scheme"])] 49 53 r#type: Option<String>, 50 54 }, 51 55 52 - /// Set an application association 56 + /// Set default application for file extension, URL scheme, or file type 53 57 Set { 54 - /// Application name or bundle identifier 55 - #[arg(value_name = "APP")] 58 + /// Application name to set as default 56 59 app_name: String, 57 60 58 - /// File extension (without dot) 59 - #[arg(long, value_name = "EXT")] 61 + /// File extension to associate (without the dot) 62 + #[arg(long, conflicts_with_all = ["scheme", "type"])] 60 63 ext: Option<String>, 61 64 62 - /// URL scheme 63 - #[arg(long, value_name = "SCHEME")] 65 + /// URL scheme to associate 66 + #[arg(long, conflicts_with_all = ["ext", "type"])] 64 67 scheme: Option<String>, 65 68 66 - /// File type/supertype 67 - #[arg(long, value_name = "TYPE")] 69 + /// File type to associate 70 + #[arg(long, conflicts_with_all = ["ext", "scheme"])] 68 71 r#type: Option<String>, 69 72 }, 70 73
+50 -8
infat-cli/src/main.rs
··· 32 32 .await 33 33 .wrap_err("Failed to load and apply configuration")?; 34 34 } 35 - Some(Commands::Info { app, ext, r#type }) => { 36 - handle_info_command(app, ext, r#type) 35 + Some(Commands::Info { 36 + app, 37 + ext, 38 + scheme, 39 + r#type, 40 + }) => { 41 + handle_info_command(app, ext, scheme, r#type) 37 42 .await 38 43 .wrap_err("Info command failed")?; 39 44 } ··· 122 127 async fn handle_info_command( 123 128 app: Option<String>, 124 129 ext: Option<String>, 130 + scheme: Option<String>, 125 131 r#type: Option<String>, 126 132 ) -> Result<()> { 127 - let provided_count = [app.is_some(), ext.is_some(), r#type.is_some()] 128 - .iter() 129 - .filter(|&&x| x) 130 - .count(); 133 + let provided_count = [ 134 + app.is_some(), 135 + ext.is_some(), 136 + scheme.is_some(), 137 + r#type.is_some(), 138 + ] 139 + .iter() 140 + .filter(|&&x| x) 141 + .count(); 131 142 132 143 // Some basic validation that clap can't provide 133 144 if provided_count == 0 { 134 145 return Err(color_eyre::eyre::eyre!( 135 - "Must provide one of: {}, {}, or {}", 146 + "Must provide one of: {}, {}, {}, or {}", 136 147 "--app".bright_yellow(), 137 148 "--ext".bright_yellow(), 149 + "--scheme".bright_yellow(), 138 150 "--type".bright_yellow() 139 151 )); 140 152 } 141 153 142 154 if provided_count > 1 { 143 155 return Err(color_eyre::eyre::eyre!( 144 - "Only one of {}, {}, or {} may be provided", 156 + "Only one of {}, {}, {}, or {} may be provided", 145 157 "--app".bright_yellow(), 146 158 "--ext".bright_yellow(), 159 + "--scheme".bright_yellow(), 147 160 "--type".bright_yellow() 148 161 )); 149 162 } ··· 230 243 println!( 231 244 "\n{}", 232 245 "No applications registered for this extension".yellow() 246 + ); 247 + } 248 + } else if let Some(url_scheme) = scheme { 249 + info!("Getting info for URL scheme: {}", url_scheme); 250 + 251 + let info = association::get_info_for_url_scheme(&url_scheme) 252 + .wrap_err_with(|| format!("Failed to get info for URL scheme: {url_scheme}"))?; 253 + 254 + println!("🔗 URL Scheme: {}", url_scheme.bright_green()); 255 + 256 + match info.default_app_name()? { 257 + Some(app_name) => { 258 + println!(" Default app: {}", app_name.bright_yellow()); 259 + } 260 + None => { 261 + println!(" Default app: {}", "None".bright_red()); 262 + } 263 + } 264 + 265 + let all_app_names = info.all_app_names(); 266 + if !all_app_names.is_empty() { 267 + println!("\n{}", "All registered apps:".bright_blue().bold()); 268 + for app_name in all_app_names { 269 + println!(" • {app_name}"); 270 + } 271 + } else { 272 + println!( 273 + "\n{}", 274 + "No applications registered for this scheme".yellow() 233 275 ); 234 276 } 235 277 } else if let Some(type_name) = r#type {