Skip to content

Commit 34e6abb

Browse files
authored
feat: show help message when no arguments provided (#20)
1 parent bff856d commit 34e6abb

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

src/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use std::path::PathBuf;
2121
version,
2222
before_help = "",
2323
about = "Backend.AI SSH - Parallel command execution across cluster nodes",
24-
long_about = "bssh is a high-performance parallel SSH command execution tool for cluster management, built with Rust.\nIt enables efficient execution of commands across multiple nodes simultaneously with real-time output streaming.\nThe tool provides secure file transfer capabilities using SFTP protocol and supports multiple authentication\nmethods including SSH keys (with passphrase support), SSH agent, and password authentication.\nIt automatically detects Backend.AI multi-node session environments.",
24+
long_about = "bssh is a high-performance parallel SSH command execution tool for cluster management.\nIt enables efficient execution of commands across multiple nodes simultaneously with real-time output streaming.\nThe tool provides secure file transfer capabilities using SFTP protocol and supports multiple authentication\nmethods including SSH keys (with passphrase support), SSH agent, and password authentication.\nIt automatically detects Backend.AI multi-node session environments.",
2525
after_help = "EXAMPLES:\n Execute command on hosts: bssh -H \"user@host1,host2\" \"uptime\"\n Use cluster configuration: bssh -c production \"df -h\"\n Upload files with glob: bssh -c staging upload \"*.log\" /tmp/\n Download from all nodes: bssh -c web download /var/log/app.log ./logs/\n Interactive mode (multiplex): bssh -c production interactive\n Test connectivity: bssh -c staging ping\n\nDeveloped and maintained as part of the Backend.AI project.\nFor more examples and documentation, visit: https://github.com/lablup/bssh"
2626
)]
2727
pub struct Cli {

src/main.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
use anyhow::Result;
16-
use clap::Parser;
16+
use clap::{CommandFactory, Parser};
1717
use std::path::{Path, PathBuf};
1818
use std::time::Duration;
1919

@@ -33,6 +33,13 @@ use bssh::{
3333
utils::init_logging,
3434
};
3535

36+
/// Show help message and exit
37+
fn show_help() {
38+
let mut cmd = Cli::command();
39+
let _ = cmd.print_help();
40+
eprintln!(); // Add a newline after help
41+
}
42+
3643
/// Format a Duration into a human-readable string
3744
fn format_duration(duration: Duration) -> String {
3845
let total_seconds = duration.as_secs_f64();
@@ -61,13 +68,20 @@ fn format_duration(duration: Duration) -> String {
6168

6269
#[tokio::main]
6370
async fn main() -> Result<()> {
71+
// Check if no arguments were provided
72+
let args: Vec<String> = std::env::args().collect();
73+
if args.len() == 1 {
74+
// Show help when no arguments provided
75+
show_help();
76+
std::process::exit(0);
77+
}
78+
6479
let cli = Cli::parse();
6580

6681
// Initialize logging
6782
init_logging(cli.verbose);
6883

6984
// Check if user explicitly specified options
70-
let args: Vec<String> = std::env::args().collect();
7185
let has_explicit_config = args.iter().any(|arg| arg == "--config");
7286
let has_explicit_parallel = args.iter().any(|arg| {
7387
arg == "-p"

0 commit comments

Comments
 (0)