mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-02 05:57:46 +00:00
commit
88ab6cfff7
1 changed files with 10 additions and 13 deletions
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "printenv"]
|
#![crate_name = "printenv"]
|
||||||
#![feature(collections, core, old_io, os, rustc_private)]
|
#![feature(rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -15,8 +15,8 @@
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
use std::os;
|
use std::env;
|
||||||
use std::old_io::print;
|
use std::io::Write;
|
||||||
|
|
||||||
#[path = "../common/util.rs"]
|
#[path = "../common/util.rs"]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
@ -31,7 +31,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
getopts::optflag("h", "help", "display this help and exit"),
|
getopts::optflag("h", "help", "display this help and exit"),
|
||||||
getopts::optflag("V", "version", "output version information and exit"),
|
getopts::optflag("V", "version", "output version information and exit"),
|
||||||
];
|
];
|
||||||
let matches = match getopts::getopts(args.tail(), &opts) {
|
let matches = match getopts::getopts(&args[1..], &opts) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(f) => {
|
Err(f) => {
|
||||||
crash!(1, "Invalid options\n{}", f)
|
crash!(1, "Invalid options\n{}", f)
|
||||||
|
@ -43,7 +43,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
println!("Usage:");
|
println!("Usage:");
|
||||||
println!(" {0} [VARIABLE]... [OPTION]...", program);
|
println!(" {0} [VARIABLE]... [OPTION]...", program);
|
||||||
println!("");
|
println!("");
|
||||||
print(getopts::usage("Prints the given environment VARIABLE(s), otherwise prints them all.", &opts).as_slice());
|
print!("{}", getopts::usage("Prints the given environment VARIABLE(s), otherwise prints them all.", &opts));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if matches.opt_present("version") {
|
if matches.opt_present("version") {
|
||||||
|
@ -62,19 +62,16 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
|
|
||||||
pub fn exec(args: Vec<String>, separator: &str) {
|
pub fn exec(args: Vec<String>, separator: &str) {
|
||||||
if args.is_empty() {
|
if args.is_empty() {
|
||||||
let vars = os::env();
|
for (env_var, value) in env::vars() {
|
||||||
for (env_var, value) in vars.into_iter() {
|
print!("{}={}{}", env_var, value, separator);
|
||||||
print!("{0}={1}", env_var, value);
|
|
||||||
print(separator);
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for env_var in args.iter() {
|
for env_var in args.iter() {
|
||||||
match os::getenv(env_var.as_slice()) {
|
match env::var(env_var) {
|
||||||
Some(var) => {
|
Ok(var) => {
|
||||||
print(var.as_slice());
|
print!("{}{}", var, separator);
|
||||||
print(separator);
|
|
||||||
}
|
}
|
||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue