From 6d10774fc85562f18e30e9b3adc61179dc683925 Mon Sep 17 00:00:00 2001 From: Brian Grinstead Date: Tue, 10 Jan 2017 10:53:34 -0800 Subject: [PATCH] Move the bin to src and take on clap dependency for command line arg parsing. Fixes #150. r=rnewman --- .travis.yml | 3 +-- Cargo.toml | 9 +-------- README.md | 11 ++++++++--- cli/Cargo.toml | 7 ------- cli/README.md | 3 --- cli/src/main.rs | 20 -------------------- src/main.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 55 insertions(+), 43 deletions(-) delete mode 100644 cli/Cargo.toml delete mode 100644 cli/README.md delete mode 100644 cli/src/main.rs create mode 100644 src/main.rs diff --git a/.travis.yml b/.travis.yml index eb808d4a..0d880700 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,5 +2,4 @@ language: rust script: - cargo build --verbose - cargo test --verbose - - cargo test --verbose -p mentat_query_parser - - cargo test --verbose -p mentat_cli + - cargo test --verbose -p mentat_query_parser \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 358ad43b..ecf0f84f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,7 @@ authors = ["Richard Newman ", "Nicholas Alexander = env::args().collect(); - println!("I got {:?} arguments: {:?}.", args.len() - 1, &args[1..]); -} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 00000000..fdbbf515 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,45 @@ +// Copyright 2016 Mozilla +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +extern crate clap; + +use clap::{App, Arg, SubCommand, AppSettings}; + +fn main() { + let app = App::new("Mentat").setting(AppSettings::ArgRequiredElseHelp); + let matches = app.subcommand(SubCommand::with_name("serve") + .about("Starts a server") + .arg(Arg::with_name("debug") + .long("debug") + .help("Print debugging info")) + .arg(Arg::with_name("database") + .short("d") + .long("database") + .value_name("FILE") + .help("Path to the Mentat database to serve") + .default_value("temp.db") + .takes_value(true)) + .arg(Arg::with_name("port") + .short("p") + .long("port") + .value_name("INTEGER") + .help("Port to serve from, i.e. `localhost:PORT`") + .default_value("3333") + .takes_value(true))) + .get_matches(); + if let Some(ref matches) = matches.subcommand_matches("serve") { + let debug = matches.is_present("debug"); + println!("This doesn't work yet, but it will eventually serve the following database: {} \ + on port: {}. Debugging={}", + matches.value_of("database").unwrap(), + matches.value_of("port").unwrap(), + debug); + } +}