~genbyte/confindent

Configuration format based on indentation
7c6af4ef — genuinebyte a month ago
Add todo.sr.ht link to top of readme
1d2ce81e — genuinebyte a month ago
Bump patch version for crates.io
8d2aa0b4 — genuinebyte a month ago
Update readme

refs

master
browse  log 

clone

read-only
https://git.sr.ht/~genbyte/confindent
read/write
git@git.sr.ht:~genbyte/confindent

You can also use your local clone with git send-email.

Confindent

Tickets are here.

Configuration by indentation. Read the spec inspired by the format of the ssh client configuration commonly found on Linux machines at ~/.ssh/config.

Read configuration from a file
extern crate confindent;
use confindent::{ConfParent, Confindent};

fn main() {
    //Read example.conf from the examples directory
    let conf = Confindent::from_file("examples/example.conf").unwrap();

    //Get the host section
    let host = conf.child("Host").unwrap();
    //Get the value of the host section
    let hostname: String = host.get().unwrap();
    //Get the value of the username subsection
    let username: String = host.child_value("Username").unwrap();
    //Get the value of the password subsection
    let password: String = host.child_value("Password").unwrap();

    println!("ssh {}@{} -p {}", username, hostname, password);

    //Result:
    //ssh user@example.com -p pass
}
Write cconfiguration to a file
extern crate confindent;
use confindent::{ConfParent, Confindent};

fn main() {
    let mut conf = Confindent::new();
    conf.create("Host", "example.net").create("Idle", "3600");
    conf.child_mut("Host")
        .unwrap()
        .create("Username", "gerald")
        .create("Password", "qwerty");
    
    conf.to_file("example.conf").unwrap();
    /*
    Yields the file `example.conf` with contents:
    
    Host example.net
        Password qwerty
        Username gerald
    Idle 3600
    */
}