Skip to content

Commit

Permalink
handle --destdir arg in --install subcommand
Browse files Browse the repository at this point in the history
Signed-off-by: onur-ozkan <[email protected]>
  • Loading branch information
onur-ozkan committed Mar 3, 2024
1 parent 2ef4867 commit 0974ab6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions lpm/cli_parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ name = "cli_parser"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
common = { path = "../common" }
logger = { path = "../../libs/logger" }
22 changes: 20 additions & 2 deletions lpm/cli_parser/src/install.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use std::collections::HashSet;

#[derive(Debug, Default, PartialEq)]
use common::some_or_error;

#[derive(Debug, PartialEq)]
pub struct InstallArgs<'a> {
pub packages: HashSet<&'a str>,
pub destdir: &'a str,
pub from_local_package: bool,
pub print_help: bool,
// TODO:
Expand All @@ -11,12 +14,26 @@ pub struct InstallArgs<'a> {
// workspace: Option<String>,
}

impl<'a> Default for InstallArgs<'a> {
fn default() -> Self {
InstallArgs {
packages: HashSet::default(),
destdir: "/",
from_local_package: false,
print_help: false,
}
}
}

impl<'a> InstallArgs<'a> {
pub(crate) fn parse(iter: &mut dyn Iterator<Item = &'a String>) -> Self {
let mut args = InstallArgs::default();

for arg in iter {
while let Some(arg) = iter.next() {
match arg.as_str() {
"--destdir" | "-d" => {
args.destdir = some_or_error!(iter.next(), "Value for '--destdir' is missing. Check 'lpm --install --help' for more information.");
}
"--local" | "-L" => {
args.from_local_package = true;
}
Expand All @@ -40,6 +57,7 @@ impl<'a> InstallArgs<'a> {
"Usage: lpm --install [FLAGS] <List of package names or Path>/[OPTION]
Options:
-d, --destdir <Target path> Installs package to specified path, similar to GNU DESTDIR (https://www.gnu.org/prep/standards/html_node/DESTDIR.html).
-h, --help Print help
Flags:
Expand Down
2 changes: 1 addition & 1 deletion lpm/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ macro_rules! some_or_error {
($fn: expr, $log: expr, $($args: tt)+) => {
match $fn {
Some(val) => val,
None => {
None => {
logger::error!("{}", format!($log, $($args)+));
std::process::exit(101);
},
Expand Down
1 change: 1 addition & 0 deletions sdk/src/high_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ extern "C" fn install_lod_file(pkg_path: *const std::os::raw::c_char) -> ResultC
ctx,
&InstallArgs {
packages: HashSet::from([pkg_path]),
destdir: "/",
from_local_package: true,
print_help: false,
},
Expand Down

0 comments on commit 0974ab6

Please sign in to comment.