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
3 changes: 2 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ path = "src/main.rs"

[dependencies]
anyhow = "1.0"
libc = "0.2"
clap = { version = "4.4", features = ["derive"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
3 changes: 3 additions & 0 deletions src/cli/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ pub struct Cli {
#[arg(long)]
pub summary: bool,

#[arg(long, help = "Suppress output on success")]
pub silent: bool,

#[command(subcommand)]
pub command: Option<Commands>,
}
Expand Down
5 changes: 5 additions & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ const SUMMARY: &str = "Manage AI context rules across different AI coding agents
pub fn run_cli() -> anyhow::Result<()> {
let cli = Cli::parse();

if cli.silent {
#[cfg(unix)]
crate::suppress_stdout();
}

if cli.summary {
println!("{SUMMARY}");
return Ok(());
Expand Down
22 changes: 17 additions & 5 deletions src/commands/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,14 @@ pub fn run_status(
);

let status = check_project_status(current_dir, args, use_claude_skills)?;
let exit_code = compute_exit_code(&status);

print_status_results(&status);

if exit_code != 0 {
std::process::exit(exit_code);
}

Ok(())
}

Expand Down Expand Up @@ -204,11 +210,21 @@ fn check_skill_files(
skills_gen.check_skills(current_dir)
}

fn compute_exit_code(status: &ProjectStatus) -> i32 {
if !status.has_ai_rules {
return 2;
}
if status.body_files_out_of_sync || status.agent_statuses.values().any(|&in_sync| !in_sync) {
return 1;
}
0
}

fn print_status_results(status: &ProjectStatus) {
if !status.has_ai_rules {
println!(" 📝 No AI rules found in this project");
println!("\n💡 Run 'ai-rules init' to get started");
std::process::exit(2);
return;
}

if status.body_files_out_of_sync {
Expand All @@ -226,10 +242,6 @@ fn print_status_results(status: &ProjectStatus) {
}

print_next_steps(status);

if status.body_files_out_of_sync || status.agent_statuses.values().any(|&in_sync| !in_sync) {
std::process::exit(1);
}
}

fn print_next_steps(status: &ProjectStatus) {
Expand Down
13 changes: 13 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,16 @@ fn main() {
std::process::exit(1);
}
}

/// Redirect stdout to /dev/null so all `println!` calls become no-ops.
/// Stderr remains unaffected.
#[cfg(unix)]
pub fn suppress_stdout() {
use std::fs::File;
use std::os::unix::io::AsRawFd;
if let Ok(devnull) = File::open("/dev/null") {
unsafe {
libc::dup2(devnull.as_raw_fd(), libc::STDOUT_FILENO);
}
}
}