Add clap command parser
This commit is contained in:
parent
c6e652c12b
commit
e91115cbe4
5 changed files with 211 additions and 45 deletions
140
Cargo.lock
generated
140
Cargo.lock
generated
|
@ -8,6 +8,17 @@ version = "1.0.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
||||
|
||||
[[package]]
|
||||
name = "atty"
|
||||
version = "0.2.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.0.1"
|
||||
|
@ -18,6 +29,7 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
|
|||
name = "autoconfig"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"dirs",
|
||||
"flate2",
|
||||
"reqwest",
|
||||
|
@ -92,6 +104,38 @@ version = "1.0.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "3.0.0-beta.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4bd1061998a501ee7d4b6d449020df3266ca3124b941ec56cf2005c3779ca142"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"bitflags",
|
||||
"clap_derive",
|
||||
"indexmap",
|
||||
"lazy_static",
|
||||
"os_str_bytes",
|
||||
"strsim",
|
||||
"termcolor",
|
||||
"textwrap",
|
||||
"unicode-width",
|
||||
"vec_map",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "3.0.0-beta.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "370f715b81112975b1b69db93e0b56ea4cd4e5002ac43b2da8474106a54096a1"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation"
|
||||
version = "0.9.1"
|
||||
|
@ -286,6 +330,15 @@ version = "0.11.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c"
|
||||
dependencies = [
|
||||
"unicode-segmentation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.19"
|
||||
|
@ -555,6 +608,12 @@ dependencies = [
|
|||
"vcpkg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "os_str_bytes"
|
||||
version = "2.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "afb2e1c3ee07430c2cf76151675e583e0f19985fa6efae47d6848a3e2c824f85"
|
||||
|
||||
[[package]]
|
||||
name = "percent-encoding"
|
||||
version = "2.1.0"
|
||||
|
@ -585,6 +644,30 @@ version = "0.2.10"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
|
||||
dependencies = [
|
||||
"proc-macro-error-attr",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error-attr"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.28"
|
||||
|
@ -800,6 +883,12 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.74"
|
||||
|
@ -836,6 +925,24 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termcolor"
|
||||
version = "1.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
|
||||
dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "textwrap"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "203008d98caf094106cfaba70acfed15e18ed3ddb7d94e49baec153a2b462789"
|
||||
dependencies = [
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.26"
|
||||
|
@ -971,6 +1078,18 @@ dependencies = [
|
|||
"tinyvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-segmentation"
|
||||
version = "1.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-width"
|
||||
version = "0.1.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.2"
|
||||
|
@ -995,6 +1114,18 @@ version = "0.2.15"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
||||
|
||||
[[package]]
|
||||
name = "vec_map"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
|
||||
|
||||
[[package]]
|
||||
name = "want"
|
||||
version = "0.3.0"
|
||||
|
@ -1105,6 +1236,15 @@ version = "0.4.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-util"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
|
|
|
@ -14,6 +14,7 @@ zip = "0.5"
|
|||
tar = "0.4"
|
||||
flate2 = "1.0"
|
||||
dirs = "3.0"
|
||||
clap = "3.0.0-beta.2"
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
winreg = "0.9"
|
72
src/main.rs
72
src/main.rs
|
@ -1,19 +1,40 @@
|
|||
use clap::{Clap};
|
||||
|
||||
use crate::installer::{
|
||||
Installer,
|
||||
utils::{
|
||||
file_utils::InstallType,
|
||||
configure::{
|
||||
configure,
|
||||
ConfigMode
|
||||
}
|
||||
},
|
||||
git::{
|
||||
GitConfig,
|
||||
GitFileIdentifier
|
||||
}
|
||||
};
|
||||
|
||||
mod installer;
|
||||
mod packages;
|
||||
|
||||
|
||||
#[derive(Clap, Debug)]
|
||||
#[clap(name = "autoconfig")]
|
||||
struct CommandArgs {
|
||||
#[clap(short, long)]
|
||||
install: Option<String>,
|
||||
}
|
||||
|
||||
fn process() -> Result<(), String> {
|
||||
let command_args = CommandArgs::parse();
|
||||
|
||||
match command_args.install {
|
||||
Some(package) => match package.as_str() {
|
||||
"fvm" => installer::process(Installer::GIT(packages::fvm::get_fvm_config()), ConfigMode::INSTALL),
|
||||
package => Err(format!("Package {} not found", package))
|
||||
},
|
||||
None => {
|
||||
println!("[INFO] Package list : [fvm]");
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
if let Err(err) = configure(&ConfigMode::INSTALL) {
|
||||
|
@ -21,46 +42,7 @@ fn main() {
|
|||
return;
|
||||
}
|
||||
|
||||
let fvm_config : GitConfig = GitConfig {
|
||||
package: String::from("leoafarias/fvm"),
|
||||
version: String::from("latest"),
|
||||
git_identifiers: vec![
|
||||
GitFileIdentifier {
|
||||
os_name: String::from("windows"),
|
||||
arch: String::from("x86_64"),
|
||||
os_identifier: String::from("windows"),
|
||||
arch_identifier: String::from("x64")
|
||||
},
|
||||
GitFileIdentifier {
|
||||
os_name: String::from("windows"),
|
||||
arch: String::from("x86"),
|
||||
os_identifier: String::from("windows"),
|
||||
arch_identifier: String::from("ia32")
|
||||
},
|
||||
GitFileIdentifier {
|
||||
os_name: String::from("macos"),
|
||||
arch: String::from("x86_64"),
|
||||
os_identifier: String::from("macos"),
|
||||
arch_identifier: String::from("x64")
|
||||
},
|
||||
GitFileIdentifier {
|
||||
os_name: String::from("linux"),
|
||||
arch: String::from("x86_64"),
|
||||
os_identifier: String::from("linux"),
|
||||
arch_identifier: String::from("x64")
|
||||
},
|
||||
GitFileIdentifier {
|
||||
os_name: String::from("linux"),
|
||||
arch: String::from("x86"),
|
||||
os_identifier: String::from("linux"),
|
||||
arch_identifier: String::from("ia32")
|
||||
}
|
||||
],
|
||||
install_type: InstallType::Command,
|
||||
archive_subfolder: String::from("fvm")
|
||||
};
|
||||
|
||||
if let Err(err) = installer::process(Installer::GIT(fvm_config), ConfigMode::INSTALL) {
|
||||
if let Err(err) = process() {
|
||||
eprintln!("[ERROR] {}", err);
|
||||
return;
|
||||
}
|
||||
|
|
42
src/packages/fvm.rs
Normal file
42
src/packages/fvm.rs
Normal file
|
@ -0,0 +1,42 @@
|
|||
use crate::installer::{git::{GitConfig, GitFileIdentifier}, utils::file_utils::InstallType};
|
||||
|
||||
pub fn get_fvm_config() -> GitConfig {
|
||||
GitConfig {
|
||||
package: String::from("leoafarias/fvm"),
|
||||
version: String::from("latest"),
|
||||
git_identifiers: vec![
|
||||
GitFileIdentifier {
|
||||
os_name: String::from("windows"),
|
||||
arch: String::from("x86_64"),
|
||||
os_identifier: String::from("windows"),
|
||||
arch_identifier: String::from("x64")
|
||||
},
|
||||
GitFileIdentifier {
|
||||
os_name: String::from("windows"),
|
||||
arch: String::from("x86"),
|
||||
os_identifier: String::from("windows"),
|
||||
arch_identifier: String::from("ia32")
|
||||
},
|
||||
GitFileIdentifier {
|
||||
os_name: String::from("macos"),
|
||||
arch: String::from("x86_64"),
|
||||
os_identifier: String::from("macos"),
|
||||
arch_identifier: String::from("x64")
|
||||
},
|
||||
GitFileIdentifier {
|
||||
os_name: String::from("linux"),
|
||||
arch: String::from("x86_64"),
|
||||
os_identifier: String::from("linux"),
|
||||
arch_identifier: String::from("x64")
|
||||
},
|
||||
GitFileIdentifier {
|
||||
os_name: String::from("linux"),
|
||||
arch: String::from("x86"),
|
||||
os_identifier: String::from("linux"),
|
||||
arch_identifier: String::from("ia32")
|
||||
}
|
||||
],
|
||||
install_type: InstallType::Command,
|
||||
archive_subfolder: String::from("fvm")
|
||||
}
|
||||
}
|
1
src/packages/mod.rs
Normal file
1
src/packages/mod.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub mod fvm;
|
Reference in a new issue