initial commit: reads table-less keys from argument only
This commit is contained in:
45
src/main.rs
Normal file
45
src/main.rs
Normal file
@@ -0,0 +1,45 @@
|
||||
// Copyright (c) 2022 Emma Tebibyte
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/* Tomcat is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* Tomcat is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see https://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::path::Path;
|
||||
|
||||
use toml::Value;
|
||||
|
||||
fn main() {
|
||||
let arguments: Vec<String> = env::args().collect();
|
||||
let argv0 = &arguments[0];
|
||||
let input = &arguments[2];
|
||||
let mut content = String::new();
|
||||
|
||||
let file = Path::new(&input);
|
||||
if file.is_file() {
|
||||
let mut content = String::new();
|
||||
File::open(file).expect("").read_to_string(&mut content).unwrap();
|
||||
println!("{}", content);
|
||||
} else { content = input.to_string(); }
|
||||
|
||||
let keyval: Vec<&str> = arguments[1].split(".").collect();
|
||||
let mut toml = content.parse::<Value>().unwrap();
|
||||
|
||||
match toml.get(keyval[1]) {
|
||||
Some(value) => println!("{}", value),
|
||||
None => println!("{}: {}: No such table or key.", argv0, arguments[1]),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user