Skip to content
Open
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
6 changes: 5 additions & 1 deletion crates/dwell-cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
pub verbose: u8,
pub quiet: bool,
pub json: bool,
pub log_level: Option<String>,
}

pub fn run(cli: Cli) -> dwell_core::Result<()> {
Expand All @@ -29,13 +30,16 @@
verbose,
quiet,
json,
log_file: _,
log_level,
command,
} = cli;
let cli_ref = CliRef {
dry_run,
verbose,
quiet,
json,
log_level,
};
let cfg = dwell_core::Config::load(&_config)?;

Expand Down Expand Up @@ -120,7 +124,7 @@
use crate::output::Output;

pub fn run(_cli: &CliRef) {
let out = Output::new(_cli.json, _cli.verbose, _cli.quiet);
let out = Output::new(_cli.json, _cli.verbose, _cli.quiet, _cli.log_level.clone());
out.title("dwell doctor — system health check");

for (name, default) in &[
Expand Down Expand Up @@ -153,7 +157,7 @@
Some(p) => out.info(&format!("dwell.toml not yet created at {}", p.display())),
None => out.error("Cannot determine config directory"),
}

Check warning on line 160 in crates/dwell-cli/src/commands.rs

View workflow job for this annotation

GitHub Actions / check

Diff in /home/runner/work/dwell/dwell/crates/dwell-cli/src/commands.rs
let source_path = dirs::data_dir().map(|d| d.join("dwell"));
match &source_path {
Some(p) if p.exists() => out.success(&format!("Source directory exists at {}", p.display())),
Expand Down
2 changes: 1 addition & 1 deletion crates/dwell-cli/src/commands/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::output::Output;

pub fn run(cli: &CliRef, _cfg: &dwell_core::Config, path: PathBuf) -> dwell_core::Result<()> {
let _ = _cfg;
let out = Output::new(cli.json, cli.verbose, cli.quiet);
let out = Output::new(cli.json, cli.verbose, cli.quiet, cli.log_level.clone());
let source_dir = resolve_source(cli, None)?;
let home = resolve_home();

Expand Down
2 changes: 1 addition & 1 deletion crates/dwell-cli/src/commands/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn run(
force: bool,
) -> dwell_core::Result<()> {
let _ = _cfg;
let out = Output::new(cli.json, cli.verbose, cli.quiet);
let out = Output::new(cli.json, cli.verbose, cli.quiet, cli.log_level.clone());
let source_dir = resolve_source(cli, source)?;
let home = resolve_home();

Expand Down
2 changes: 1 addition & 1 deletion crates/dwell-cli/src/commands/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn run(
no_packages: bool,
dry_run: bool,
) -> dwell_core::Result<()> {
let out = Output::new(cli.json, cli.verbose, cli.quiet);
let out = Output::new(cli.json, cli.verbose, cli.quiet, cli.log_level.clone());
let source_dir = crate::commands::resolve_source(cli, source)?;
let home = crate::commands::resolve_home();

Expand Down
2 changes: 1 addition & 1 deletion crates/dwell-cli/src/commands/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn run(
_cfg: &dwell_core::Config,
action: crate::DepsCommand,
) -> dwell_core::Result<()> {
let out = Output::new(cli.json, cli.verbose, cli.quiet);
let out = Output::new(cli.json, cli.verbose, cli.quiet, cli.log_level.clone());

match action {
crate::DepsCommand::Scan { source } => cmd_scan(&out, source),
Expand Down
2 changes: 1 addition & 1 deletion crates/dwell-cli/src/commands/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub fn run(
source: Option<PathBuf>,
) -> dwell_core::Result<()> {
let _ = _cfg;
let out = Output::new(cli.json, cli.verbose, cli.quiet);
let out = Output::new(cli.json, cli.verbose, cli.quiet, cli.log_level.clone());
let source_dir = resolve_source(cli, source)?;
let home = resolve_home();

Expand Down
2 changes: 1 addition & 1 deletion crates/dwell-cli/src/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn run(
) -> dwell_core::Result<()> {
let _ = _cfg;
let _ = _remote_url;
let out = Output::new(cli.json, cli.verbose, cli.quiet);
let out = Output::new(cli.json, cli.verbose, cli.quiet, cli.log_level.clone());

let source_dir = source.unwrap_or_else(|| {
dirs::data_dir()
Expand Down
2 changes: 1 addition & 1 deletion crates/dwell-cli/src/commands/module_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub fn run(
_cfg: &dwell_core::Config,
action: crate::ModuleCommand,
) -> dwell_core::Result<()> {
let out = Output::new(cli.json, cli.verbose, cli.quiet);
let out = Output::new(cli.json, cli.verbose, cli.quiet, cli.log_level.clone());
let reg = ModuleRegistry::new();

match action {
Expand Down
8 changes: 4 additions & 4 deletions crates/dwell-cli/src/commands/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn run(

/// Install all declared system packages.
fn cmd_install(cli: &CliRef, cfg: &dwell_core::Config) -> dwell_core::Result<()> {
let out = Output::new(cli.json, cli.verbose, cli.quiet);
let out = Output::new(cli.json, cli.verbose, cli.quiet, cli.log_level.clone());
let registry = dwell_package::PackageManagerRegistry::new();

let backend = registry.detect().ok_or_else(|| {
Expand Down Expand Up @@ -65,7 +65,7 @@ fn cmd_install(cli: &CliRef, cfg: &dwell_core::Config) -> dwell_core::Result<()>

/// List all installed packages per backend, marking declared ones with `*`.
fn cmd_list(cli: &CliRef, cfg: &dwell_core::Config) -> dwell_core::Result<()> {
let out = Output::new(cli.json, cli.verbose, cli.quiet);
let out = Output::new(cli.json, cli.verbose, cli.quiet, cli.log_level.clone());
let registry = dwell_package::PackageManagerRegistry::new();
let declared: Vec<&str> = cfg.packages.system.iter().map(|s| s.as_str()).collect();

Expand Down Expand Up @@ -101,7 +101,7 @@ fn cmd_list(cli: &CliRef, cfg: &dwell_core::Config) -> dwell_core::Result<()> {

/// Remove all declared packages via the first available backend.
fn cmd_remove(cli: &CliRef, cfg: &dwell_core::Config) -> dwell_core::Result<()> {
let out = Output::new(cli.json, cli.verbose, cli.quiet);
let out = Output::new(cli.json, cli.verbose, cli.quiet, cli.log_level.clone());
let registry = dwell_package::PackageManagerRegistry::new();

let backend = registry.detect().ok_or_else(|| {
Expand Down Expand Up @@ -147,7 +147,7 @@ fn cmd_remove(cli: &CliRef, cfg: &dwell_core::Config) -> dwell_core::Result<()>

/// Show package drift — declared vs installed.
fn cmd_diff(cli: &CliRef, cfg: &dwell_core::Config) -> dwell_core::Result<()> {
let out = Output::new(cli.json, cli.verbose, cli.quiet);
let out = Output::new(cli.json, cli.verbose, cli.quiet, cli.log_level.clone());
let registry = dwell_package::PackageManagerRegistry::new();

let backend = registry.detect().ok_or_else(|| {
Expand Down
2 changes: 1 addition & 1 deletion crates/dwell-cli/src/commands/reset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn run(
source: Option<PathBuf>,
dry_run: bool,
) -> dwell_core::Result<()> {
let out = Output::new(cli.json, cli.verbose, cli.quiet);
let out = Output::new(cli.json, cli.verbose, cli.quiet, cli.log_level.clone());
let source_dir = crate::commands::resolve_source(cli, source)?;
let home = crate::commands::resolve_home();

Expand Down
2 changes: 1 addition & 1 deletion crates/dwell-cli/src/commands/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub fn run(
_cfg: &dwell_core::Config,
action: crate::SetupCommand,
) -> dwell_core::Result<()> {
let out = Output::new(cli.json, cli.verbose, cli.quiet);
let out = Output::new(cli.json, cli.verbose, cli.quiet, cli.log_level.clone());

match action {
crate::SetupCommand::Capture {
Expand Down
2 changes: 1 addition & 1 deletion crates/dwell-cli/src/commands/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub fn run(
source: Option<PathBuf>,
) -> dwell_core::Result<()> {
let _ = _cfg;
let out = Output::new(cli.json, cli.verbose, cli.quiet);
let out = Output::new(cli.json, cli.verbose, cli.quiet, cli.log_level.clone());
let source_dir = resolve_source(cli, source)?;

out.info(&format!("Checking status of {}", source_dir.display()));
Expand Down
2 changes: 1 addition & 1 deletion crates/dwell-cli/src/commands/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn run(
source: Option<PathBuf>,
dry_run: bool,
) -> dwell_core::Result<()> {
let out = Output::new(cli.json, cli.verbose, cli.quiet);
let out = Output::new(cli.json, cli.verbose, cli.quiet, cli.log_level.clone());
let source_dir = crate::commands::resolve_source(cli, source)?;
let git_dir = source_dir.join(".git");

Expand Down
2 changes: 1 addition & 1 deletion crates/dwell-cli/src/commands/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub fn run(
source: Option<PathBuf>,
) -> dwell_core::Result<()> {
let _ = _cfg;
let out = Output::new(cli.json, cli.verbose, cli.quiet);
let out = Output::new(cli.json, cli.verbose, cli.quiet, cli.log_level.clone());
let source_dir = resolve_source(cli, source)?;

out.info(&format!("Watching {}", source_dir.display()));
Expand Down
51 changes: 39 additions & 12 deletions crates/dwell-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@
#[arg(long)]
pub json: bool,

/// Log file path (default: stderr)
#[arg(long)]
pub log_file: Option<PathBuf>,

/// Log level override [possible values: error, warn, info, debug, trace]
#[arg(long)]
pub log_level: Option<String>,

#[command(subcommand)]
pub command: Commands,
}
Expand Down Expand Up @@ -326,21 +334,40 @@
fn main() {
let cli = Cli::parse();

// Configure logging
let level = match cli.verbose {
0 => "warn",
1 => "info",
2 => "debug",
_ => "trace",
};

tracing_subscriber::fmt()
// Determine log level

Check warning on line 337 in crates/dwell-cli/src/main.rs

View workflow job for this annotation

GitHub Actions / check

Diff in /home/runner/work/dwell/dwell/crates/dwell-cli/src/main.rs
let level = cli.log_level.clone().unwrap_or_else(|| {
match cli.verbose {
0 => if cli.quiet { "error" } else { "warn" },
1 => "info",
2 => "debug",
_ => "trace",
}.to_string()

Check warning on line 344 in crates/dwell-cli/src/main.rs

View workflow job for this annotation

GitHub Actions / check

Diff in /home/runner/work/dwell/dwell/crates/dwell-cli/src/main.rs
});

// Configure tracing subscriber with optional file output
let builder = tracing_subscriber::fmt()
.with_env_filter(format!("dwell={}", level))
.with_writer(std::io::stderr)
.without_time()
.init();
.with_target(false)
.without_time();

if let Some(ref log_path) = cli.log_file {
use std::fs::OpenOptions;
let file = OpenOptions::new()
.create(true)
.append(true)

Check warning on line 357 in crates/dwell-cli/src/main.rs

View workflow job for this annotation

GitHub Actions / check

Diff in /home/runner/work/dwell/dwell/crates/dwell-cli/src/main.rs
.open(log_path)
.unwrap_or_else(|e| {
eprintln!("dwell: warning: cannot open log file {}: {}", log_path.display(), e);
// Fallback to stderr using /dev/null as a dummy that won't matter
std::fs::File::create("/dev/null").unwrap()
});
builder.with_writer(std::sync::Mutex::new(file)).init();
} else {
builder.with_writer(std::io::stderr).init();
}

if let Err(e) = commands::run(cli) {
// Always print fatal errors to stderr regardless of log config
eprintln!("dwell: error: {}", e);
std::process::exit(1);
}
Expand Down
Loading
Loading