Merge pull request #160 from sixpounder/master
Add command line argument to allow a no-fork mode
This commit is contained in:
commit
634a24717f
1 changed files with 34 additions and 28 deletions
62
src/main.rs
62
src/main.rs
|
|
@ -71,13 +71,41 @@ pub fn icon_cache_get(name: &'static str, size: u16) -> widget::icon::Icon {
|
||||||
/// Runs application with these settings
|
/// Runs application with these settings
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let mut shell_program_opt = None;
|
||||||
|
let mut shell_args = Vec::new();
|
||||||
|
let mut parse_flags = true;
|
||||||
|
let mut daemonize = true;
|
||||||
|
for arg in env::args().skip(1) {
|
||||||
|
if parse_flags {
|
||||||
|
match arg.as_str() {
|
||||||
|
// These flags indicate the end of parsing flags
|
||||||
|
"-e" | "--command" | "--" => {
|
||||||
|
parse_flags = false;
|
||||||
|
}
|
||||||
|
"--no-daemon" => {
|
||||||
|
daemonize = false;
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
//TODO: should this throw an error?
|
||||||
|
log::warn!("ignored argument {:?}", arg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if shell_program_opt.is_none() {
|
||||||
|
shell_program_opt = Some(arg);
|
||||||
|
} else {
|
||||||
|
shell_args.push(arg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(all(unix, not(target_os = "redox")))]
|
#[cfg(all(unix, not(target_os = "redox")))]
|
||||||
match fork::daemon(true, true) {
|
if daemonize {
|
||||||
Ok(fork::Fork::Child) => (),
|
match fork::daemon(true, true) {
|
||||||
Ok(fork::Fork::Parent(_child_pid)) => process::exit(0),
|
Ok(fork::Fork::Child) => (),
|
||||||
Err(err) => {
|
Ok(fork::Fork::Parent(_child_pid)) => process::exit(0),
|
||||||
eprintln!("failed to daemonize: {err:?}");
|
Err(err) => {
|
||||||
process::exit(1);
|
eprintln!("failed to daemonize: {:?}", err);
|
||||||
|
process::exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -102,28 +130,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut shell_program_opt = None;
|
|
||||||
let mut shell_args = Vec::new();
|
|
||||||
let mut parse_flags = true;
|
|
||||||
for arg in env::args().skip(1) {
|
|
||||||
if parse_flags {
|
|
||||||
match arg.as_str() {
|
|
||||||
// These flags indicate the end of parsing flags
|
|
||||||
"-e" | "--command" | "--" => {
|
|
||||||
parse_flags = false;
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
//TODO: should this throw an error?
|
|
||||||
log::warn!("ignored argument {:?}", arg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if shell_program_opt.is_none() {
|
|
||||||
shell_program_opt = Some(arg);
|
|
||||||
} else {
|
|
||||||
shell_args.push(arg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let startup_options = if let Some(shell_program) = shell_program_opt {
|
let startup_options = if let Some(shell_program) = shell_program_opt {
|
||||||
let options = tty::Options {
|
let options = tty::Options {
|
||||||
shell: Some(tty::Shell::new(shell_program, shell_args)),
|
shell: Some(tty::Shell::new(shell_program, shell_args)),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue