1#![forbid(unsafe_code)]
2
3use std::ffi::{OsStr, OsString};
4
5mod cli;
6mod commands;
7mod config;
8mod index;
9mod manifest;
10mod output;
11mod project;
12
13use anyhow::Result;
14use clap::Parser;
15
16use crate::cli::Cli;
17
18pub fn run() -> Result<()> {
19 run_from(std::env::args_os())
20}
21
22pub fn run_cargo_subcommand() -> Result<()> {
23 run_from(cargo_subcommand_args())
24}
25
26fn run_from<I, T>(args: I) -> Result<()>
27where
28 I: IntoIterator<Item = T>,
29 T: Into<OsString> + Clone,
30{
31 let cli = Cli::parse_from(args);
32 commands::run(cli)
33}
34
35fn cargo_subcommand_args() -> Vec<OsString> {
36 let mut raw_args = std::env::args_os();
37 let mut args = Vec::new();
38
39 if let Some(binary) = raw_args.next() {
40 args.push(binary);
41 }
42
43 match raw_args.next() {
44 Some(first) if first.as_os_str() == OsStr::new("rustuse") => {}
45 Some(first) => args.push(first),
46 None => {}
47 }
48
49 args.extend(raw_args);
50 args
51}