mirror of
https://github.com/uutils/coreutils
synced 2024-11-16 17:58:06 +00:00
hostname: ensure that this works on Windows and improve help menu
This commit is contained in:
parent
79acabb381
commit
9d432b0a26
1 changed files with 14 additions and 5 deletions
|
@ -36,11 +36,11 @@ fn main () {
|
||||||
|
|
||||||
let matches = match getopts(args.tail(), options) {
|
let matches = match getopts(args.tail(), options) {
|
||||||
Ok(m) => { m }
|
Ok(m) => { m }
|
||||||
_ => { println!("{:s}", usage(program, options)); return; }
|
_ => { help_menu(program, options); return; }
|
||||||
};
|
};
|
||||||
|
|
||||||
if matches.opt_present("h") {
|
if matches.opt_present("h") {
|
||||||
println!("{:s}", usage(program, options));
|
help_menu(program, options);
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if matches.opt_present("V") { version(); return }
|
if matches.opt_present("V") { version(); return }
|
||||||
|
@ -60,16 +60,25 @@ fn main () {
|
||||||
println!("{:s}", hostname);
|
println!("{:s}", hostname);
|
||||||
}
|
}
|
||||||
1 => { xsethostname( matches.free.last().unwrap() ) }
|
1 => { xsethostname( matches.free.last().unwrap() ) }
|
||||||
_ => { println!("{:s}", usage(program, options)); }
|
_ => { help_menu(program, options); }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn version() {
|
fn version() {
|
||||||
println!("hostname version 1.0.0");
|
println!("hostname 1.0.0");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn help_menu(program: &str, options: &[getopts::OptGroup]) {
|
||||||
|
version();
|
||||||
|
println!("");
|
||||||
|
println!("Usage:");
|
||||||
|
println!(" {:s} [OPTION]... [HOSTNAME]", program);
|
||||||
|
println!("");
|
||||||
|
print!("{:s}", usage("Print or set the system's host name.", options));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn xgethostname() -> ~str {
|
fn xgethostname() -> ~str {
|
||||||
let namelen = 255u;
|
let namelen = 256u;
|
||||||
let mut name = vec::from_elem(namelen, 0u8);
|
let mut name = vec::from_elem(namelen, 0u8);
|
||||||
|
|
||||||
let err = unsafe {
|
let err = unsafe {
|
||||||
|
|
Loading…
Reference in a new issue