Defined cli program options

This commit is contained in:
Nathan Fisher 2023-03-24 12:51:54 -04:00
parent c3324f203b
commit d6982b70e8
9 changed files with 320 additions and 5 deletions

125
Cargo.lock generated
View File

@ -52,6 +52,9 @@ name = "cc"
version = "1.0.79" version = "1.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f"
dependencies = [
"jobserver",
]
[[package]] [[package]]
name = "cfg-if" name = "cfg-if"
@ -81,6 +84,13 @@ dependencies = [
"os_str_bytes", "os_str_bytes",
] ]
[[package]]
name = "cli"
version = "0.1.0"
dependencies = [
"clap",
]
[[package]] [[package]]
name = "cpufeatures" name = "cpufeatures"
version = "0.2.5" version = "0.2.5"
@ -244,6 +254,15 @@ version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "form_urlencoded"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8"
dependencies = [
"percent-encoding",
]
[[package]] [[package]]
name = "funty" name = "funty"
version = "2.0.0" version = "2.0.0"
@ -286,12 +305,15 @@ name = "hpk"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"clap", "clap",
"cli",
"rayon", "rayon",
"ron", "ron",
"serde", "serde",
"sha2", "sha2",
"tar", "tar",
"url",
"walkdir", "walkdir",
"zstd",
] ]
[[package]] [[package]]
@ -300,6 +322,16 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
[[package]]
name = "idna"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6"
dependencies = [
"unicode-bidi",
"unicode-normalization",
]
[[package]] [[package]]
name = "indexmap" name = "indexmap"
version = "1.9.2" version = "1.9.2"
@ -333,6 +365,15 @@ dependencies = [
"windows-sys", "windows-sys",
] ]
[[package]]
name = "jobserver"
version = "0.1.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.140" version = "0.2.140"
@ -382,6 +423,18 @@ version = "6.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ceedf44fb00f2d1984b0bc98102627ce622e083e49a5bacdb3e514fa4238e267" checksum = "ceedf44fb00f2d1984b0bc98102627ce622e083e49a5bacdb3e514fa4238e267"
[[package]]
name = "percent-encoding"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e"
[[package]]
name = "pkg-config"
version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160"
[[package]] [[package]]
name = "proc-macro-crate" name = "proc-macro-crate"
version = "1.3.1" version = "1.3.1"
@ -581,6 +634,21 @@ dependencies = [
"syn 2.0.4", "syn 2.0.4",
] ]
[[package]]
name = "tinyvec"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50"
dependencies = [
"tinyvec_macros",
]
[[package]]
name = "tinyvec_macros"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]] [[package]]
name = "toml_datetime" name = "toml_datetime"
version = "0.6.1" version = "0.6.1"
@ -604,12 +672,39 @@ version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
[[package]]
name = "unicode-bidi"
version = "0.3.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460"
[[package]] [[package]]
name = "unicode-ident" name = "unicode-ident"
version = "1.0.8" version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4"
[[package]]
name = "unicode-normalization"
version = "0.1.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921"
dependencies = [
"tinyvec",
]
[[package]]
name = "url"
version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643"
dependencies = [
"form_urlencoded",
"idna",
"percent-encoding",
"serde",
]
[[package]] [[package]]
name = "version_check" name = "version_check"
version = "0.9.4" version = "0.9.4"
@ -740,3 +835,33 @@ checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed"
dependencies = [ dependencies = [
"tap", "tap",
] ]
[[package]]
name = "zstd"
version = "0.12.3+zstd.1.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76eea132fb024e0e13fd9c2f5d5d595d8a967aa72382ac2f9d39fcc95afd0806"
dependencies = [
"zstd-safe",
]
[[package]]
name = "zstd-safe"
version = "6.0.4+zstd.1.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7afb4b54b8910cf5447638cb54bf4e8a65cbedd783af98b98c62ffe91f185543"
dependencies = [
"libc",
"zstd-sys",
]
[[package]]
name = "zstd-sys"
version = "2.0.7+zstd.1.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94509c3ba2fe55294d752b79842c530ccfab760192521df74a081a78d2b3c7f5"
dependencies = [
"cc",
"libc",
"pkg-config",
]

View File

@ -7,20 +7,33 @@ license = "GPL-3.0-only"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[workspace] [workspace]
members = [ "tar" ] members = [ "cli", "tar" ]
[[bin]]
name = "hpk"
path = "src/hpk.rs"
[workspace.dependencies]
clap = "4.1"
[dependencies] [dependencies]
clap = "4.1" clap = { workspace = true }
cli = { path = "cli" }
rayon = "1.7" rayon = "1.7"
ron = "0.8" ron = "0.8"
sha2 = "0.10" sha2 = "0.10"
tar = { path = "tar" } tar = { path = "tar" }
walkdir = "2.3" walkdir = "2.3"
zstd = "0.12"
[dependencies.serde] [dependencies.serde]
version = "1.0" version = "1.0"
features = ["derive"] features = ["derive"]
[dependencies.url]
version = "2.3"
features = ["serde"]
[profile.release] [profile.release]
codegen-units = 1 codegen-units = 1
lto = true lto = true

8
cli/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "cli"
version = "0.1.0"
edition = "2021"
license = "GPL-3.0-only"
[dependencies]
clap = { workspace = true }

118
cli/src/lib.rs Normal file
View File

@ -0,0 +1,118 @@
use clap::{Arg, ArgAction, Command, ValueHint, value_parser};
pub fn cli() -> Command {
Command::new("hpk")
.about("A package manager for HitchHiker Linux")
.author("Nathan Fisher")
.version(env!("CARGO_PKG_VERSION"))
.propagate_version(true)
.arg_required_else_help(true)
.subcommands([
create(),
search(),
install(),
remove(),
upgrade(),
])
}
fn create() -> Command {
Command::new("create")
.about("Create a new package from a directory of files")
.args([
Arg::new("directory")
.help("the directory where the files are located [default: current working directory]")
.num_args(1),
Arg::new("specs")
.help("path to the package specs file in `ron` format")
.short('s')
.long("specs")
.conflicts_with_all(["name", "package-version", "release", "dependencies"])
.num_args(1),
Arg::new("name")
.help("package name")
.short('n')
.long("name")
.num_args(1)
.required_unless_present("specs"),
Arg::new("package-version")
.help("package version")
.short('v')
.long("package-version")
.num_args(1)
.required_unless_present("specs"),
Arg::new("release")
.help("release number")
.short('r')
.long("release")
.default_value("1")
.value_parser(value_parser!(usize)),
Arg::new("dependencies")
.help("a comma separated list of dependencies")
.short('d')
.long("dependencies")
.value_delimiter(',')
.num_args(1..),
])
}
fn search() -> Command {
Command::new("search")
.about("Search for packages")
.visible_alias("se")
.args([
Arg::new("installed")
.help("only list installed packages")
.short('i')
.long("installed")
.action(ArgAction::SetTrue),
Arg::new("remote")
.help("do not list installed packages")
.short('r')
.long("remote")
.conflicts_with("installed")
.action(ArgAction::SetTrue),
Arg::new("names")
.help("only search in package names, not descriptions")
.short('n')
.long("names")
.action(ArgAction::SetTrue),
Arg::new("query")
.use_value_delimiter(false)
.required(true),
])
}
fn install() -> Command {
Command::new("install")
.about("Install packages")
.visible_aliases(["in", "add"])
.args([
Arg::new("package")
.required_unless_present("local")
.conflicts_with("local")
.num_args(1..),
Arg::new("local")
.help("install a package from the filesystem")
.short('l')
.long("local")
.value_name("package")
.value_hint(ValueHint::FilePath)
.num_args(1..),
])
}
fn remove() -> Command {
Command::new("remove")
.about("Remove packages")
.visible_aliases(["rm", "del"])
.arg(Arg::new("package")
.required(true)
.num_args(1..))
}
fn upgrade() -> Command {
Command::new("upgrade")
.about("Upgrade packages")
.visible_aliases(["update", "up", "sync"])
}

38
src/hpk.rs Normal file
View File

@ -0,0 +1,38 @@
use {
clap::ArgMatches,
cli::cli,
std::error::Error,
};
fn main() -> Result<(), Box<dyn Error>> {
let matches = cli().get_matches();
match matches.subcommand() {
Some(("create", matches)) => create(matches)?,
Some(("search", matches)) => search(matches)?,
Some(("install", matches)) => install(matches)?,
Some(("remove", matches)) => remove(matches)?,
Some(("upgrade", _)) => upgrade()?,
_ => {}
}
Ok(())
}
fn create(_matches: &ArgMatches) -> Result<(), Box<dyn Error>> {
unimplemented!();
}
fn search(_matches: &ArgMatches) -> Result<(), Box<dyn Error>> {
unimplemented!();
}
fn install(_matches: &ArgMatches) -> Result<(), Box<dyn Error>> {
unimplemented!();
}
fn remove(_matches: &ArgMatches) -> Result<(), Box<dyn Error>> {
unimplemented!();
}
fn upgrade() -> Result<(), Box<dyn Error>> {
unimplemented!();
}

View File

@ -2,10 +2,13 @@
mod item; mod item;
mod package; mod package;
mod plist; mod plist;
mod repository;
mod version; mod version;
pub use { pub use {
item::Item, item::Item,
package::{Dependency, Package}, package::{Dependency, Package},
plist::*, plist::*,
repository::Repository,
version::*, version::*,
}; };

View File

@ -1,3 +0,0 @@
fn main() {
println!("Hello, world!");
}

View File

@ -27,4 +27,5 @@ pub struct Package {
dependencies: Vec<Dependency>, dependencies: Vec<Dependency>,
users: Option<Vec<User>>, users: Option<Vec<User>>,
groups: Option<Vec<Group>>, groups: Option<Vec<Group>>,
post_install: Option<String>,
} }

12
src/repository/mod.rs Normal file
View File

@ -0,0 +1,12 @@
use {
crate::Package,
serde::{Deserialize, Serialize},
std::collections::HashMap,
url::Url,
};
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Repository {
pub base_url: Url,
pub packages: HashMap<String, Package>,
}