Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "star-setup"
version = "0.3.2"
version = "0.3.3"
edition = "2021"
repository = "https://github.com/star-setup/core"
description = "Lightweight CLI to clone, configure, and wire single or multi-repo ecosystems"
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,13 @@ build-mono/
Profiles represent a saved ecosystem of libraries commonly used together.
```bash
# Add a profile
star-setup --profile-add myprofile user/lib1 user/lib2
star-setup profile add myprofile user/lib1 user/lib2

# List profiles
star-setup --list-profiles
star-setup profile list

# Remove a profile
star-setup --profile-remove myprofile
star-setup profile remove myprofile

# Use a profile
star-setup username/repo --profile myprofile
Expand All @@ -190,16 +190,16 @@ Config files are checked in this order:

```bash
# Initialize a default config file
star-setup --init-config
star-setup config init

# Add a named config
star-setup --config-add myconfig --ssh --build-type Release
star-setup config add myconfig --ssh --build-type Release

# List configs
star-setup --list-configs
star-setup config list

# Remove a config
star-setup --config-remove myconfig
star-setup config remove myconfig

# Use a config
star-setup username/repo --config myconfig
Expand Down
27 changes: 18 additions & 9 deletions src/cli/args.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
use crate::{
cli::{
resolve_with_config, BuildFlags, ConfigFlags, ConnectionFlags, DiagnosticFlags, MonoRepoFlags,
ProfileFlags, ResolvedArgs,
commands::{ConfigCommand, ProfileCommand},
resolve_with_config, BuildFlags, ConnectionFlags, DiagnosticFlags, MonoRepoFlags, ResolvedArgs,
},
config::SetupConfig,
};
use clap::Parser;
use clap::{Parser, Subcommand};

#[derive(Subcommand)]
pub enum Command {
/// Manage saved configurations.
Config(ConfigCommand),
/// Manage saved profiles.
Profile(ProfileCommand),
}

/// Top-level CLI arguments for star-setup.
#[derive(Parser)]
Expand All @@ -22,6 +30,13 @@ pub struct Args {
#[arg(short = 'y', long)]
pub yes: bool,

/// Select a named configuration to use
#[arg(long = "config")]
pub config_name: Option<String>,

#[command(subcommand)]
pub command: Option<Command>,

#[command(flatten)]
pub connection: ConnectionFlags,

Expand All @@ -31,12 +46,6 @@ pub struct Args {
#[command(flatten)]
pub mono: MonoRepoFlags,

#[command(flatten)]
pub config: ConfigFlags,

#[command(flatten)]
pub profile: ProfileFlags,

#[command(flatten)]
pub diagnostic: DiagnosticFlags,
}
Expand Down
62 changes: 62 additions & 0 deletions src/cli/commands.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use crate::cli::{BuildFlags, ConnectionFlags, DiagnosticFlags, MonoRepoFlags};
use clap::{Parser, Subcommand};

/// Config subcommand.
#[derive(Parser)]
pub struct ConfigCommand {
#[command(subcommand)]
pub action: ConfigAction,
}

/// Config subcommand actions.
#[derive(Subcommand)]
pub enum ConfigAction {
/// Create a default config file in the current directory.
Init,
/// Add or overwrite a named configuration entry.
Add {
/// Name of the configuration entry.
name: String,
#[command(flatten)]
connection: ConnectionFlags,
#[command(flatten)]
build: BuildFlags,
#[command(flatten)]
mono: MonoRepoFlags,
#[command(flatten)]
diagnostic: DiagnosticFlags,
},
/// Remove a named configuration entry.
Remove {
/// Name of the configuration entry to remove.
name: String,
},
/// List all saved configuration entries.
List,
}

/// Profile subcommand.
#[derive(Parser)]
pub struct ProfileCommand {
#[command(subcommand)]
pub action: ProfileAction,
}

/// Profile subcommand actions.
#[derive(Subcommand)]
pub enum ProfileAction {
/// Add or overwrite a named profile.
Add {
/// Name of the profile.
name: String,
/// Repository list (username/repo ...).
repos: Vec<String>,
},
/// Remove a named profile.
Remove {
/// Name of the profile to remove.
name: String,
},
/// List all saved profiles.
List,
}
39 changes: 0 additions & 39 deletions src/cli/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,45 +76,6 @@ pub struct MonoRepoFlags {
pub profile: Option<String>,
}

#[derive(ClapArgs)]
#[allow(clippy::struct_excessive_bools)]
pub struct ConfigFlags {
/// Create a default config file in the current directory
#[arg(long)]
pub init_config: bool,

/// Select a named configuration to use
#[arg(long = "config")]
pub config_name: Option<String>,

/// Add a new config
#[arg(long)]
pub config_add: Option<String>,

/// Remove a saved configuration
#[arg(long)]
pub config_remove: Option<String>,

/// List all saved configs
#[arg(long)]
pub list_configs: bool,
}

#[derive(ClapArgs)]
pub struct ProfileFlags {
/// Add a new profile: NAME REPO1 [REPO2 ...]
#[arg(long, num_args = 2..)]
pub profile_add: Option<Vec<String>>,

/// Remove a saved profile
#[arg(long)]
pub profile_remove: Option<String>,

/// List all saved profiles
#[arg(long)]
pub list_profiles: bool,
}

#[derive(ClapArgs)]
pub struct DiagnosticFlags {
/// Show timing information for each phase
Expand Down
6 changes: 3 additions & 3 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ pub use args::Args;
pub mod build;
pub use build::{detect_build_system, detect_mono_build_system, BuildSystem, BuildType};
pub mod flags;
pub use flags::{
BuildFlags, ConfigFlags, ConnectionFlags, DiagnosticFlags, MonoRepoFlags, ProfileFlags,
};
pub use flags::{BuildFlags, ConnectionFlags, DiagnosticFlags, MonoRepoFlags};
pub mod resolve;
pub use resolve::{resolve_bool, resolve_with_config};
pub mod resolved;
pub use resolved::{
ResolvedArgs, ResolvedBuildFlags, ResolvedConnectionFlags, ResolvedDiagnosticFlags,
ResolvedMonoFlags,
};
pub mod commands;
pub use commands::{ConfigAction, ConfigCommand, ProfileAction, ProfileCommand};
6 changes: 2 additions & 4 deletions src/cli/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ pub fn resolve_bool(positive: bool, negative: bool, config: Option<bool>, defaul
/// # Errors
/// Returns an error if the named config does not exist in the provided `SetupConfig`.
pub fn resolve_with_config(mut args: Args, config: &SetupConfig) -> Result<ResolvedArgs, String> {
let config_name = args.config.config_name.as_deref().unwrap_or("default");
if let Some(name) = &args.config.config_name {
let config_name = args.config_name.as_deref().unwrap_or("default");
if let Some(name) = &args.config_name {
if !config.configs.contains_key(name.as_str()) {
return Err(format!("Configuration '{name}' not found"));
}
Expand Down Expand Up @@ -111,7 +111,5 @@ pub fn resolve_with_config(mut args: Args, config: &SetupConfig) -> Result<Resol
repos,
profile,
},
config: args.config,
profile: args.profile,
})
}
4 changes: 1 addition & 3 deletions src/cli/resolved.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::cli::{BuildSystem, BuildType, ConfigFlags, ProfileFlags};
use crate::cli::{BuildSystem, BuildType};

/// Resolved connection flags after applying config and CLI overrides.
pub struct ResolvedConnectionFlags {
Expand Down Expand Up @@ -39,6 +39,4 @@ pub struct ResolvedArgs {
pub diagnostic: ResolvedDiagnosticFlags,
pub build: ResolvedBuildFlags,
pub mono: ResolvedMonoFlags,
pub config: ConfigFlags,
pub profile: ProfileFlags,
}
29 changes: 28 additions & 1 deletion src/config/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::cli::{BuildType, ResolvedArgs};
use crate::cli::{BuildFlags, BuildType, ConnectionFlags, DiagnosticFlags, MonoRepoFlags, ResolvedArgs};
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, path::PathBuf};

Expand Down Expand Up @@ -30,6 +30,33 @@ pub struct ConfigEntry {
pub meson_flags: Vec<String>,
}

impl ConfigEntry {
/// Creates a `ConfigEntry` from raw flag structs.
/// # Errors
/// Returns an error if the build type string cannot be parsed.
#[must_use]
pub fn from_flags(
connection: &ConnectionFlags,
build: &BuildFlags,
mono: &MonoRepoFlags,
diagnostic: &DiagnosticFlags,
) -> Self {
Self {
ssh: connection.ssh,
build_type: build.build_type.as_deref().unwrap_or("debug").parse().unwrap_or_default(),
build_dir: build.build_dir.clone().unwrap_or_else(|| "build".to_string()),
mono_dir: mono.mono_dir.clone().unwrap_or_else(|| "build-mono".to_string()),
no_build: build.no_build,
clean: build.clean,
verbose: connection.verbose,
timing: diagnostic.timing,
dry_run: diagnostic.dry_run,
cmake_flags: build.cmake_flags.clone(),
meson_flags: build.meson_flags.clone(),
}
}
}

impl From<&ResolvedArgs> for ConfigEntry {
fn from(args: &ResolvedArgs) -> Self {
Self {
Expand Down
Loading
Loading