Move the bin to src and take on clap dependency for command line arg parsing. Fixes #150. r=rnewman

This commit is contained in:
Brian Grinstead 2017-01-10 10:53:34 -08:00 committed by GitHub
parent daddfd3e0f
commit 6d10774fc8
7 changed files with 55 additions and 43 deletions

View file

@ -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

View file

@ -5,6 +5,7 @@ authors = ["Richard Newman <rnewman@twinql.com>", "Nicholas Alexander <nalexande
[dependencies]
rusqlite = "0.8.0"
clap = "2.19.3"
[dependencies.edn]
path = "edn"
@ -14,11 +15,3 @@ rusqlite = "0.8.0"
[dependencies.mentat_query_parser]
path = "query-parser"
[dev-dependencies]
[dev-dependencies.mentat_cli]
path = "cli"
[[bin]]
name = "mentat_cli"
path = "cli/src/main.rs"

View file

@ -81,13 +81,18 @@ cargo test
cargo test -p mentat_query_parser
````
To start the cli use:
To start the server use:
````
cargo run
cargo run serve
````
For most `cargo` commands you can pass the `-p` argument to run the command just on that package. By convention, the package name will be "mentat_package_name". So, `cargo build -p mentat_cli` will build just the "cli" folder.
To pass in custom arguments to the cli through Cargo, you'll need to pass `--` after the command to ensure they get passed properly. For example:
````
cargo run serve -- --help
````
For most `cargo` commands you can pass the `-p` argument to run the command just on that package. So, `cargo build -p mentat_query_parser` will build just the "query-parser" folder.
## License

View file

@ -1,7 +0,0 @@
[package]
name = "mentat_cli"
version = "0.0.1"
[dependencies]
[dependencies.mentat]
path = "../"

View file

@ -1,3 +0,0 @@
# mentat-cli
Note: this isn't actually doing anything and is just a placeholder to get the project structure in place.

View file

@ -1,20 +0,0 @@
// 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.
use std::env;
extern crate mentat;
// This is just a placeholder to get the project structure in place.
fn main() {
println!("Loaded {}", mentat::get_name());
let args: Vec<String> = env::args().collect();
println!("I got {:?} arguments: {:?}.", args.len() - 1, &args[1..]);
}

45
src/main.rs Normal file
View file

@ -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);
}
}