Skip to content
This repository was archived by the owner on May 15, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ description = "A third-party cargo extension to allow you to open a dependent cr
name = "cargo-open"

[dependencies]
clap = "*"
clap = "~1.4"
cargo = "*"
20 changes: 17 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extern crate clap;
extern crate cargo;

use clap::{Arg, App, AppSettings, SubCommand};
use cargo::core::SourceId;
use cargo::core::{SourceId};
use cargo::util::{hex, CargoResult};

use std::env;
Expand All @@ -26,11 +26,25 @@ fn main() {
.help("The name of the crate you would like to open")
.required(true)
.index(1)))
.settings(&[AppSettings::SubcommandRequired])
.arg(Arg::with_name("CRATE")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

COOL!!! 🆒 🆒 🆒

.help("The name of the crate you would like to open")
.required(true))
.setting(AppSettings::SubcommandsNegateReqs)
.get_matches();

// Ok to use unwrap here because clap will handle argument errors
let crate_name = matches.subcommand_matches("open").unwrap().value_of("CRATE").unwrap();
let crate_name = match matches.value_of("CRATE") {
Some(c) => {
if env::var_os("CARGO_HOME").is_none() {
// TODO: set CARGO_HOME env var
}
c
},
None => matches.subcommand_matches("open")
.unwrap()
.value_of("CRATE")
.unwrap()
};

let crate_dir = match cargo_dir(crate_name) {
Ok(path) => path,
Expand Down