Skip to content

Commit

Permalink
Implement "cargo init"
Browse files Browse the repository at this point in the history
When non-existing directory is provided as argument, it
works just like "cargo new".

When existing directory is used, it may also create template
source file like "cargo new" or may find and use existing
source code for Cargo.toml.

Squashed commit of the following:

    cargo init: Supply USER envvar for one test
    cargo init: Other message when Cargo.toml already exists
    cargo init: Resolve conflict after with #2257
    fix minor issues
    cargo new/init: Simplify error handling code in entry points
    cargo new/init: Better message for invalid characters in name
    cargo init: fix minor issues in test
    cargo init: Avoid excessive builds in the test
    cargo init: minor fixes
    cargo init: Skip no_filename test on Windows
    cargo init: Implement better error message for bin name clash
    cargo init: minor fixes
    cargo init: handle "/" path
    cargo init: Actualise
    cargo new: Fix upper case error message in test
    cargo init: Remove paths::{file,directory}_already_exists
    fix uppper-case error messages
    cargo init: Fix minor issues per diff comments
    cargo init: Change binary handling
    cargo init: Move multiple lib error detection away from mk
    cargo init: Support optional path argument
    cargo init: Fix minor issues per Github comments
    cargo init: Fix complaint from tests/check-style.sh
    cargo init: Handle projects with multiple mains
    cargo init: Major refactor, multi-target projects
    cargo init: Add Cargo.lock unconditionally
    cargo init: Fix complains from tests/check-style.sh
    cargo init: Tests for handling VCS
    cargo init: Handle VCS
    cargo init: work in progress
    cargo init: Deduplicate some things between new and init
    cargo init: Auto-detection of --bin
    cargo init: work in progress...
    cargo init: Fix tests and allow explicit --vcs
    cargo init: intermediate refactor
    cargo init: First sketch of implementation
    cargo init: Preliminary test
    cargo init: first stub

See
/~https://github.com/vi/cargo/tree/cargo_init_unsquashed
for individual commits
  • Loading branch information
vi committed Jan 23, 2016
1 parent 1a929a1 commit 800172f
Show file tree
Hide file tree
Showing 8 changed files with 688 additions and 46 deletions.
1 change: 1 addition & 0 deletions src/bin/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ macro_rules! each_subcommand{
$mac!(generate_lockfile);
$mac!(git_checkout);
$mac!(help);
$mac!(init);
$mac!(install);
$mac!(locate_project);
$mac!(login);
Expand Down
53 changes: 53 additions & 0 deletions src/bin/init.rs
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)
}

Loading

0 comments on commit 800172f

Please sign in to comment.