mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
commit
2b9196d6fa
1 changed files with 16 additions and 12 deletions
28
src/uu/env/src/env.rs
vendored
28
src/uu/env/src/env.rs
vendored
|
@ -12,6 +12,9 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate clap;
|
extern crate clap;
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate uucore;
|
||||||
|
|
||||||
use clap::{App, AppSettings, Arg};
|
use clap::{App, AppSettings, Arg};
|
||||||
use ini::Ini;
|
use ini::Ini;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
@ -19,6 +22,7 @@ use std::env;
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
use std::iter::Iterator;
|
use std::iter::Iterator;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
use uucore::error::{UResult, USimpleError};
|
||||||
|
|
||||||
const USAGE: &str = "env [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]";
|
const USAGE: &str = "env [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]";
|
||||||
const AFTER_HELP: &str = "\
|
const AFTER_HELP: &str = "\
|
||||||
|
@ -70,7 +74,7 @@ fn parse_program_opt<'a>(opts: &mut Options<'a>, opt: &'a str) -> Result<(), i32
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_config_file(opts: &mut Options) -> Result<(), i32> {
|
fn load_config_file(opts: &mut Options) -> UResult<()> {
|
||||||
// NOTE: config files are parsed using an INI parser b/c it's available and compatible with ".env"-style files
|
// NOTE: config files are parsed using an INI parser b/c it's available and compatible with ".env"-style files
|
||||||
// ... * but support for actual INI files, although working, is not intended, nor claimed
|
// ... * but support for actual INI files, although working, is not intended, nor claimed
|
||||||
for &file in &opts.files {
|
for &file in &opts.files {
|
||||||
|
@ -157,7 +161,7 @@ pub fn uu_app() -> App<'static, 'static> {
|
||||||
.help("remove variable from the environment"))
|
.help("remove variable from the environment"))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_env(args: impl uucore::Args) -> Result<(), i32> {
|
fn run_env(args: impl uucore::Args) -> UResult<()> {
|
||||||
let app = uu_app();
|
let app = uu_app();
|
||||||
let matches = app.get_matches_from(args);
|
let matches = app.get_matches_from(args);
|
||||||
|
|
||||||
|
@ -188,8 +192,10 @@ fn run_env(args: impl uucore::Args) -> Result<(), i32> {
|
||||||
match env::set_current_dir(d) {
|
match env::set_current_dir(d) {
|
||||||
Ok(()) => d,
|
Ok(()) => d,
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
eprintln!("env: cannot change directory to \"{}\": {}", d, error);
|
return Err(USimpleError::new(
|
||||||
return Err(125);
|
125,
|
||||||
|
format!("cannot change directory to \"{}\": {}", d, error),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -253,9 +259,9 @@ fn run_env(args: impl uucore::Args) -> Result<(), i32> {
|
||||||
|
|
||||||
// FIXME: this should just use execvp() (no fork()) on Unix-like systems
|
// FIXME: this should just use execvp() (no fork()) on Unix-like systems
|
||||||
match Command::new(&*prog).args(args).status() {
|
match Command::new(&*prog).args(args).status() {
|
||||||
Ok(exit) if !exit.success() => return Err(exit.code().unwrap()),
|
Ok(exit) if !exit.success() => return Err(exit.code().unwrap().into()),
|
||||||
Err(ref err) if err.kind() == io::ErrorKind::NotFound => return Err(127),
|
Err(ref err) if err.kind() == io::ErrorKind::NotFound => return Err(127.into()),
|
||||||
Err(_) => return Err(126),
|
Err(_) => return Err(126.into()),
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -266,9 +272,7 @@ fn run_env(args: impl uucore::Args) -> Result<(), i32> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uumain(args: impl uucore::Args) -> i32 {
|
#[uucore_procs::gen_uumain]
|
||||||
match run_env(args) {
|
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
Ok(()) => 0,
|
run_env(args)
|
||||||
Err(code) => code,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue