-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #2081 - vi:cargo_init, r=alexcrichton
Implement `cargo init` command and appropriate tests ( #21). Features: * Working like `cargo new` if there are no files in current directory * Auto-detection of `--bin` * Auto-detection of already existing VSC and appending to respecive ignore file * Appending of appropriate `[lib]` or `[[bin]]` section to `Cargo.toml` in case of some non-standard source locations Concerns: * I'm not experienced in Rust + lazy => code looks poorer compared to the rest Cargo code * The test don't cover 100% of functions * Project consisting of both binary and library is not handled * Many deviations from [previously proposed algorithm](#2008 (comment))
- Loading branch information
Showing
8 changed files
with
688 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use std::env; | ||
|
||
use cargo::ops; | ||
use cargo::util::{CliResult, Config}; | ||
|
||
#[derive(RustcDecodable)] | ||
struct Options { | ||
flag_verbose: bool, | ||
flag_quiet: bool, | ||
flag_color: Option<String>, | ||
flag_bin: bool, | ||
arg_path: Option<String>, | ||
flag_name: Option<String>, | ||
flag_vcs: Option<ops::VersionControl>, | ||
} | ||
|
||
pub const USAGE: &'static str = " | ||
Create a new cargo package in current directory | ||
Usage: | ||
cargo init [options] [<path>] | ||
cargo init -h | --help | ||
Options: | ||
-h, --help Print this message | ||
--vcs VCS Initialize a new repository for the given version | ||
control system (git or hg) or do not initialize any version | ||
control at all (none) overriding a global configuration. | ||
--bin Use a binary instead of a library template | ||
--name NAME Set the resulting package name | ||
-v, --verbose Use verbose output | ||
-q, --quiet No output printed to stdout | ||
--color WHEN Coloring: auto, always, never | ||
"; | ||
|
||
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> { | ||
debug!("executing; cmd=cargo-init; args={:?}", env::args().collect::<Vec<_>>()); | ||
try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); | ||
try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); | ||
|
||
let Options { flag_bin, arg_path, flag_name, flag_vcs, .. } = options; | ||
|
||
let opts = ops::NewOptions { | ||
version_control: flag_vcs, | ||
bin: flag_bin, | ||
path: &arg_path.unwrap_or(format!(".")), | ||
name: flag_name.as_ref().map(|s| s.as_ref()), | ||
}; | ||
|
||
try!(ops::init(opts, config)); | ||
Ok(None) | ||
} | ||
|
Oops, something went wrong.