forked from manoeldesouza/zc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit. Interface reasonably functional but no operation is e…
…nabled yet.
- Loading branch information
0 parents
commit 37bb316
Showing
7 changed files
with
515 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/target | ||
/.vscode |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# zc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.