2020-04-08 12:19:50 -07:00
|
|
|
use crate::common::*;
|
|
|
|
|
|
|
|
pub(crate) struct Bin {
|
2020-04-16 04:16:40 -07:00
|
|
|
path: PathBuf,
|
2020-04-30 21:21:20 -07:00
|
|
|
pub(crate) subcommands: Vec<BinSubcommand>,
|
2020-04-08 12:19:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Bin {
|
|
|
|
#[throws]
|
2020-04-16 04:16:40 -07:00
|
|
|
pub(crate) fn new(path: &Path) -> Bin {
|
2020-04-08 12:19:50 -07:00
|
|
|
let mut bin = Bin {
|
2020-04-16 04:16:40 -07:00
|
|
|
path: path.into(),
|
2020-04-08 12:19:50 -07:00
|
|
|
subcommands: Vec::new(),
|
|
|
|
};
|
|
|
|
|
|
|
|
bin.add_subcommands(&mut Vec::new())?;
|
|
|
|
|
|
|
|
bin.subcommands.sort();
|
|
|
|
|
|
|
|
bin
|
|
|
|
}
|
|
|
|
|
|
|
|
#[throws]
|
|
|
|
fn add_subcommands(&mut self, command: &mut Vec<String>) {
|
2020-04-30 21:21:20 -07:00
|
|
|
let subcommand = BinSubcommand::new(&self.path, command.clone())?;
|
2020-04-08 12:19:50 -07:00
|
|
|
|
|
|
|
for name in &subcommand.subcommands {
|
|
|
|
command.push(name.into());
|
|
|
|
if name != "help" {
|
|
|
|
self.add_subcommands(command)?;
|
|
|
|
}
|
|
|
|
command.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
self.subcommands.push(subcommand);
|
|
|
|
}
|
|
|
|
}
|