Switch to arg_parser
This commit is contained in:
Generated
+4
-31
@@ -2,7 +2,7 @@
|
||||
name = "redox_installer"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"clap 2.26.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"arg_parser 0.1.0 (git+https://github.com/redox-os/arg-parser.git)",
|
||||
"liner 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"pkgutils 0.1.1 (git+https://github.com/redox-os/pkgutils.git)",
|
||||
"rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -19,11 +19,6 @@ name = "adler32"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "ansi_term"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "arg_parser"
|
||||
version = "0.1.0"
|
||||
@@ -38,16 +33,6 @@ dependencies = [
|
||||
"scoped_threadpool 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atty"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.6.0"
|
||||
@@ -90,11 +75,7 @@ name = "clap"
|
||||
version = "2.26.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"atty 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"term_size 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"textwrap 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -105,7 +86,7 @@ name = "coco"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"either 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"either 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"scopeguard 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
@@ -129,7 +110,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.1.0"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
@@ -524,11 +505,6 @@ dependencies = [
|
||||
"typenum 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "0.10.8"
|
||||
@@ -756,10 +732,8 @@ dependencies = [
|
||||
|
||||
[metadata]
|
||||
"checksum adler32 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6cbd0b9af8587c72beadc9f72d35b9fbb070982c9e6203e46e93f10df25f8f45"
|
||||
"checksum ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "23ac7c30002a5accbf7e8987d0632fa6de155b7c3d39d0067317a391e00a2ef6"
|
||||
"checksum arg_parser 0.1.0 (git+https://github.com/redox-os/arg-parser.git)" = "<none>"
|
||||
"checksum argon2rs 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3f67b0b6a86dae6e67ff4ca2b6201396074996379fba2b92ff649126f37cb392"
|
||||
"checksum atty 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d912da0db7fa85514874458ca3651fe2cddace8d0b0505571dbdcd41ab490159"
|
||||
"checksum base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "96434f987501f0ed4eb336a411e0631ecd1afa11574fe148587adc4ff96143c9"
|
||||
"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d"
|
||||
"checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5"
|
||||
@@ -771,7 +745,7 @@ dependencies = [
|
||||
"checksum constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e"
|
||||
"checksum conv 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "78ff10625fd0ac447827aa30ea8b861fead473bb60aeb73af6c1c58caf0d1299"
|
||||
"checksum custom_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "ef8ae57c4978a2acd8b869ce6b9ca1dfe817bff704c220209fdef2c0b75a01b9"
|
||||
"checksum either 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18785c1ba806c258137c937e44ada9ee7e69a37e3c72077542cd2f069d78562a"
|
||||
"checksum either 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cbee135e9245416869bf52bd6ccc9b59e2482651510784e089b874272f02a252"
|
||||
"checksum extra 0.1.0 (git+https://github.com/redox-os/libextra.git)" = "<none>"
|
||||
"checksum fuse 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5087262ce5b36fed6ccd4abf0a8224e48d055a2bb07fecb5605765de6f114a28"
|
||||
"checksum futures 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "05a23db7bd162d4e8265968602930c476f688f0c180b44bdaf55e0cb2c687558"
|
||||
@@ -820,7 +794,6 @@ dependencies = [
|
||||
"checksum serde_derive_internals 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bd381f6d01a6616cdba8530492d453b7761b456ba974e98768a18cad2cd76f58"
|
||||
"checksum spin 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7e4deb3c2455c73779e6d3eebceae9599fc70957e54c69fe88f93aa48e62f432"
|
||||
"checksum static-buffer 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6da6a96247d4b372d3ed90dec2c129ab57c934359ac4c6adbaa5871cd0737437"
|
||||
"checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694"
|
||||
"checksum syn 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)" = "58fd09df59565db3399efbba34ba8a2fec1307511ebd245d0061ff9d42691673"
|
||||
"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
|
||||
"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ name = "redox_installer"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
clap = "2.26"
|
||||
arg_parser = { git = "https://github.com/redox-os/arg-parser.git" }
|
||||
liner = "0.1"
|
||||
pkgutils = { git = "https://github.com/redox-os/pkgutils.git" }
|
||||
rand = "0.3"
|
||||
|
||||
+14
-40
@@ -1,54 +1,29 @@
|
||||
#![deny(warnings)]
|
||||
|
||||
extern crate clap;
|
||||
extern crate arg_parser;
|
||||
extern crate redox_installer;
|
||||
extern crate serde;
|
||||
extern crate toml;
|
||||
|
||||
use std::process;
|
||||
use std::{env, io, process};
|
||||
use std::fs::File;
|
||||
use std::io::{self, Read, Write};
|
||||
use std::io::{Read, Write};
|
||||
use std::path::Path;
|
||||
|
||||
use clap::{App, Arg};
|
||||
use arg_parser::ArgParser;
|
||||
|
||||
fn main() {
|
||||
let stderr = io::stderr();
|
||||
let mut stderr = stderr.lock();
|
||||
|
||||
let matches = App::new("redox_installer")
|
||||
.arg(
|
||||
Arg::with_name("cookbook")
|
||||
.help("Path of cookbook")
|
||||
.short("b")
|
||||
.long("cookbook")
|
||||
.takes_value(true)
|
||||
.value_name("FOLDER")
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("config")
|
||||
.help("Configuration file")
|
||||
.short("c")
|
||||
.long("config")
|
||||
.takes_value(true)
|
||||
.value_name("FILE")
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("list-packages")
|
||||
.help("List packages")
|
||||
.short("l")
|
||||
.long("list-packages")
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("output")
|
||||
.help("Output folder or device")
|
||||
.index(1)
|
||||
.value_name("OUTPUT")
|
||||
)
|
||||
.get_matches();
|
||||
let mut parser = ArgParser::new(3)
|
||||
.add_opt("b", "cookbook")
|
||||
.add_opt("c", "config")
|
||||
.add_flag(&["l", "list-packages"]);
|
||||
parser.parse(env::args());
|
||||
|
||||
let config = if let Some(path) = matches.value_of("config") {
|
||||
match File::open(path) {
|
||||
let config = if let Some(path) = parser.get_opt("config") {
|
||||
match File::open(&path) {
|
||||
Ok(mut config_file) => {
|
||||
let mut config_data = String::new();
|
||||
match config_file.read_to_string(&mut config_data) {
|
||||
@@ -90,11 +65,10 @@ fn main() {
|
||||
redox_installer::Config::default()
|
||||
};
|
||||
|
||||
let cookbook = if let Some(path) = matches.value_of("cookbook") {
|
||||
let cookbook = if let Some(path) = parser.get_opt("cookbook") {
|
||||
if ! Path::new(&path).is_dir() {
|
||||
writeln!(stderr, "installer: {}: cookbook not found", path).unwrap();
|
||||
process::exit(1);
|
||||
|
||||
}
|
||||
|
||||
Some(path)
|
||||
@@ -102,12 +76,12 @@ fn main() {
|
||||
None
|
||||
};
|
||||
|
||||
if matches.is_present("list-packages") {
|
||||
if parser.found("list-packages") {
|
||||
for (packagename, _package) in &config.packages {
|
||||
println!("{}", packagename);
|
||||
}
|
||||
} else {
|
||||
if let Some(path) = matches.value_of("output") {
|
||||
if let Some(path) = parser.args.get(0) {
|
||||
if let Err(err) = redox_installer::install(config, path, cookbook) {
|
||||
writeln!(stderr, "installer: failed to install: {}", err).unwrap();
|
||||
process::exit(1);
|
||||
|
||||
+4
-4
@@ -68,13 +68,13 @@ fn prompt_password(prompt: &str, confirm_prompt: &str) -> Result<String, String>
|
||||
}
|
||||
}
|
||||
|
||||
fn install_packages(config: &Config, dest: &str, cookbook: Option<&str>) {
|
||||
fn install_packages<S: AsRef<str>>(config: &Config, dest: &str, cookbook: Option<S>) {
|
||||
let mut repo = Repo::new(TARGET);
|
||||
repo.add_remote(REMOTE);
|
||||
|
||||
if let Some(cookbook) = cookbook {
|
||||
let status = Command::new("./repo.sh")
|
||||
.current_dir(cookbook)
|
||||
.current_dir(cookbook.as_ref())
|
||||
.args(config.packages.keys())
|
||||
.spawn()
|
||||
.unwrap()
|
||||
@@ -90,7 +90,7 @@ fn install_packages(config: &Config, dest: &str, cookbook: Option<&str>) {
|
||||
println!("Installing package {}", packagename);
|
||||
let path = format!("{}/{}/repo/{}/{}.tar.gz",
|
||||
env::current_dir().unwrap().to_string_lossy(),
|
||||
cookbook, TARGET, packagename);
|
||||
cookbook.as_ref(), TARGET, packagename);
|
||||
Package::from_path(&path).unwrap().install(dest).unwrap();
|
||||
}
|
||||
} else {
|
||||
@@ -101,7 +101,7 @@ fn install_packages(config: &Config, dest: &str, cookbook: Option<&str>) {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn install<P: AsRef<Path>>(config: Config, output: P, cookbook: Option<&str>) -> Result<(), String> {
|
||||
pub fn install<P: AsRef<Path>, S: AsRef<str>>(config: Config, output: P, cookbook: Option<S>) -> Result<(), String> {
|
||||
let output = output.as_ref();
|
||||
|
||||
println!("Install {:#?} to {}", config, output.display());
|
||||
|
||||
Reference in New Issue
Block a user