blob: 3bdc2906e5d854057d5c16837211102c81361341 [file] [log] [blame]
// Copyright 2018 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
pub mod disk;
pub mod frontends;
pub mod lsb_release;
pub mod methods;
pub mod proto;
pub mod unsafe_misc;
use std::collections::BTreeMap;
use std::env;
use std::error::Error;
use getopts::Options;
use frontends::{EnvMap, FRONTENDS};
use methods::Methods;
fn make_options() -> Options {
let mut opts = Options::new();
opts.optflag("h", "help", "print this help menu");
fn print_usage(program_name: &str, opts: &Options) {
eprintln!("Crostini client\n");
let brief = format!("USAGE: {} [SUBCOMMAND|FRONTEND]", program_name);
eprintln!("{}", opts.usage(&brief));
eprint!("Alternatively, invoke a supported FRONTEND: ");
let mut first = true;
for frontend in FRONTENDS {
if !first {
eprint!(", ");
first = false;
for frontend in FRONTENDS {
fn main() -> Result<(), Box<dyn Error>> {
let args_string: Vec<String> = env::args().collect();
let args: Vec<&str> = args_string.iter().map(|s| s.as_str()).collect();
let vars_string: BTreeMap<String, String> = env::vars().collect();
let vars: EnvMap = vars_string
.map(|(k, v)| (k.as_str(), v.as_str()))
if args.is_empty() {
print_usage("crostini_client", &make_options());
return Ok(());
// Match the program name against frontend names.
for frontend in FRONTENDS {
if args[0].ends_with( {
return Methods::new()?, &args, &vars);
if args.len() == 1 {
print_usage(&args[0], &make_options());
return Ok(());
// Next, match the subcommand against frontend names.
for frontend in FRONTENDS {
if args[1].ends_with( {
return Methods::new()?, &args[1..], &vars);
eprintln!("unrecognized frontend name: `{}`", args[0]);