diff options
author | Guillaume Pasquet <dev@etenil.net> | 2021-11-19 22:33:56 +0000 |
---|---|---|
committer | Guillaume Pasquet <dev@etenil.net> | 2021-11-19 22:33:56 +0000 |
commit | da0cd2fe49a4fba917516fd637fef6be6c304896 (patch) | |
tree | ae05d56d59edb1207e3b29ffbb76eede7bc8ec46 | |
parent | 8f0d2e928981f06b0f6d53da89356ba5baeb8422 (diff) |
Added Context structure.
-rw-r--r-- | TODO.org | 24 | ||||
-rw-r--r-- | src/main.rs | 22 |
2 files changed, 46 insertions, 0 deletions
diff --git a/TODO.org b/TODO.org new file mode 100644 index 0000000..c307705 --- /dev/null +++ b/TODO.org @@ -0,0 +1,24 @@ +* Context [25%] +** DONE Introduce context structure +** TODO Populate from env variables +** TODO Implement variable substitution in barbfiles +** TODO Carry over context across requests + +* JQ filtering [0%] +** TODO Find a JQ-like library in rust +** TODO Use library to extract data from requests +** TODO Allow multiple named filters +** TODO Store filter output in context + +* Support binary files [0%] +** TODO Have binary filepath as body +** TODO Output binary files to file system +** TODO Coerce filetype (to display seemingly binary files normally) + +* Command line options [0%] +** TODO Multiple files on the command line +** TODO Filter override +** TODO Disable filtering altogether +** TODO Override header + +* Add curses-based manager diff --git a/src/main.rs b/src/main.rs index b6255d7..81cb18d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,11 +2,33 @@ mod barbfile; use jsonformat::{format_json, Indentation}; +use std::collections::HashMap; +use std::env; use std::fs; use std::str::FromStr; use ureq; +struct Context { + vars: HashMap<String, String>, +} + +impl Context { + pub fn new() -> Context { + Context { + vars: HashMap::new(), + } + } + + pub fn get_var(&self, name: String) -> Option<String> { + self.vars + .get(&name) + .map(|val| val.clone()) + .or_else(|| env::var(name).ok()) + } +} + fn main() { + let mut context = Context::new(); let bfile = barbfile::BarbFile::from_str( fs::read_to_string("test.barb") .expect("Failed to read file") |