mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
Merge pull request #1374 from rivy/fix.env-polish
env: minor fixes and commentary polish
This commit is contained in:
commit
e1cf3a42d5
1 changed files with 6 additions and 4 deletions
10
src/env/env.rs
vendored
10
src/env/env.rs
vendored
|
@ -64,7 +64,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
"null",
|
"null",
|
||||||
"end each output line with a 0 byte rather than newline (only valid when printing the environment)",
|
"end each output line with a 0 byte rather than newline (only valid when printing the environment)",
|
||||||
)
|
)
|
||||||
.optopt("f", "file", "read and sets variables from the file (prior to sets/unsets)", "FILE")
|
.optopt("f", "file", "read and set variables from an \".env\"-style configuration file (prior to any unset and/or set)", "PATH")
|
||||||
.optopt("u", "unset", "remove variable from the environment", "NAME");
|
.optopt("u", "unset", "remove variable from the environment", "NAME");
|
||||||
|
|
||||||
let mut opts = Box::new(Options {
|
let mut opts = Box::new(Options {
|
||||||
|
@ -120,7 +120,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let var = iter.next();
|
let var = iter.next();
|
||||||
|
|
||||||
match var {
|
match var {
|
||||||
None => println!("{}: this option requires an argument: {}", NAME, opt),
|
None => eprintln!("{}: this option requires an argument: {}", NAME, opt),
|
||||||
Some(s) => opts.files.push(s.to_owned()),
|
Some(s) => opts.files.push(s.to_owned()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -159,7 +159,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let var = iter.next();
|
let var = iter.next();
|
||||||
|
|
||||||
match var {
|
match var {
|
||||||
None => println!("{}: this option requires an argument: {}", NAME, opt),
|
None => eprintln!("{}: this option requires an argument: {}", NAME, opt),
|
||||||
Some(s) => opts.files.push(s.to_owned()),
|
Some(s) => opts.files.push(s.to_owned()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -222,6 +222,8 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
for file in &opts.files {
|
for file in &opts.files {
|
||||||
let conf = if file == "-" {
|
let conf = if file == "-" {
|
||||||
let stdin = stdin();
|
let stdin = stdin();
|
||||||
|
@ -237,7 +239,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
for (_, prop) in &conf {
|
for (_, prop) in &conf { // ignore all INI section lines (treat them as comments)
|
||||||
for (key, value) in prop {
|
for (key, value) in prop {
|
||||||
env::set_var(key, value);
|
env::set_var(key, value);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue