Skip to content

Commit

Permalink
Rename and correct the flags (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
MOZGIII authored Feb 27, 2023
1 parent 9a166e9 commit 1fbdaf6
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use std::process::ExitCode;

use clap::{ArgAction, Args, Parser, Subcommand};
use clap::{Args, Parser, Subcommand};
use humanode_distribution_config::load::SourcesLoadingResult;
use humanode_distribution_resolver::resolve::Contextualized;
use humanode_distribution_schema::manifest::Package;
Expand All @@ -31,13 +31,13 @@ enum Command {

#[derive(Debug, Args)]
struct SourcesArgs {
/// Do not load the built-in sources.
#[arg(long, action = ArgAction::SetFalse, default_value_t = true)]
no_load_built_in_sources: bool,
/// Do not add the built-in sources.
#[arg(long, default_value_t = false)]
no_built_in_sources: bool,

/// Do not load the config files.
#[arg(long, action = ArgAction::SetFalse, default_value_t = true)]
no_load_config_files: bool,
#[arg(long, default_value_t = false)]
no_config_files: bool,

/// The list of URLs to fetch the repos from.
#[arg(short, long)]
Expand Down Expand Up @@ -135,6 +135,20 @@ async fn main() -> ExitCode {
ExitCode::SUCCESS
}

fn add_built_in_sources(sources: &mut humanode_distribution_config::Sources) {
let extend = |what: &mut Vec<String>, with_what: &[&str]| {
what.extend(with_what.iter().map(|&item| item.to_owned()));
};
extend(
&mut sources.repo_urls,
humanode_distribution_built_in_sources::REPO_URLS,
);
extend(
&mut sources.manifest_urls,
humanode_distribution_built_in_sources::MANIFEST_URLS,
);
}

// Load the configs, print encountered errors.
async fn load_configs(all_sources: &mut humanode_distribution_config::Sources) {
let config_paths = humanode_distribution_config::paths::configs();
Expand All @@ -161,29 +175,19 @@ async fn load_configs(all_sources: &mut humanode_distribution_config::Sources) {
/// the configs.
async fn prepare_sources(sources_args: SourcesArgs) -> humanode_distribution_config::Sources {
let SourcesArgs {
no_load_built_in_sources,
no_load_config_files,
no_built_in_sources,
no_config_files,
repo_urls,
manifest_urls,
} = sources_args;

let mut sources = humanode_distribution_config::Sources::default();

if !no_load_built_in_sources {
let extend = |what: &mut Vec<String>, with_what: &[&str]| {
what.extend(with_what.iter().map(|&item| item.to_owned()));
};
extend(
&mut sources.repo_urls,
humanode_distribution_built_in_sources::REPO_URLS,
);
extend(
&mut sources.manifest_urls,
humanode_distribution_built_in_sources::MANIFEST_URLS,
);
if !no_built_in_sources {
add_built_in_sources(&mut sources);
}

if !no_load_config_files {
if !no_config_files {
load_configs(&mut sources).await;
}

Expand Down

0 comments on commit 1fbdaf6

Please sign in to comment.