Skip to content

Commit

Permalink
Initial commit. Interface reasonably functional but no operation is e…
Browse files Browse the repository at this point in the history
…nabled yet.
  • Loading branch information
manoeldesouza committed Jul 26, 2020
0 parents commit 37bb316
Show file tree
Hide file tree
Showing 7 changed files with 515 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
/.vscode
37 changes: 37 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "zc"
version = "0.1.0"
authors = ["Manoel de Souza <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ncurses = "5.99.0"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# zc
74 changes: 74 additions & 0 deletions src/command.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@

use std::process;

pub struct CommandResult {

pub name: String,
pub used: String,
}


pub fn zfs_pools() -> Vec<CommandResult> {

vec![
CommandResult {
name: "Carolina Wildner Simm".to_string(),
used: "36".to_string()
}
]
}

pub fn zfs_dataset() -> Vec<CommandResult> {
let arguments = vec!["list", "-o", "name,used", "-H"];
run_command("zfs", &arguments)
}

pub fn zfs_volumes() -> Vec<CommandResult> {

vec![
CommandResult {
name: "Manoel de Souza e Silva Neto".to_string(),
used: "40".to_string()
}
]
}

pub fn zfs_snapshots() -> Vec<CommandResult> {
let arguments = vec!["list", "-H", "-o", "name,used", "-t", "snapshot"];
run_command("zfs", &arguments)
}

pub fn run_command(cmd: &str, arguments: &Vec<&str>) -> Vec<CommandResult> {

let mut command = process::Command::new(cmd);
let output = command.args(arguments).output().expect("Failure running command").stdout;
let command_output = String::from_utf8_lossy(&output).to_string();

let lines: Vec<&str> = command_output.split("\n").collect();

let mut result = Vec::new();

for line in lines.iter() {

let mut split = line.split_whitespace();

let name = match split.next() {
Some(n) => n.to_string(),
None => String::new(),
};

let used = match split.next() {
Some(n) => n.to_string(),
None => String::new(),
};

let command_result = CommandResult {
name: name,
used: used,
};

result.push(command_result);
}

result
}
Loading

0 comments on commit 37bb316

Please sign in to comment.