-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from ericmcbride/tokio-integration
Updated to use struct ops
- Loading branch information
Showing
4 changed files
with
21 additions
and
77 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 |
---|---|---|
|
@@ -10,3 +10,4 @@ colored = "1.7" | |
rand = "0.6.5" | ||
tokio-threadpool = "0.1.17" | ||
futures = "0.1.19" | ||
structopt = "0.3" |
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
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 |
---|---|---|
@@ -1,12 +1,11 @@ | ||
#[macro_use] | ||
extern crate clap; | ||
extern crate structopt; | ||
|
||
mod kube; | ||
mod utils; | ||
|
||
/// Main Entrypoint into the code | ||
fn main() { | ||
match run() { | ||
match kube::run() { | ||
Ok(log_config) => match kube::run_logs(&log_config) { | ||
Ok(_) => { | ||
println!("Log files are found at /tmp/<podname>"); | ||
|
@@ -20,24 +19,3 @@ fn main() { | |
} | ||
} | ||
} | ||
|
||
/// Cli options for wufei | ||
fn run() -> Result<(kube::LogRecorderConfig), Box<dyn ::std::error::Error>> { | ||
let args = clap_app!(wufei => | ||
(version: "1.0") | ||
(author: "Eric McBride <[email protected]>") | ||
(about: "View All Logs from Kubernetes Namespace") | ||
(@arg NAMESPACE: -n --namespace +required +takes_value "Namespace for logs") | ||
(@arg KUBECONFIG: -k --kubeconfig +takes_value "Kube config file if not using context") | ||
(@arg OUTFILE: -o --outfile +takes_value requires[FILE] "Outfile for --file flag") | ||
(@arg FILE: -f --file "Write logs to files based on pod name /tmp/podname") | ||
(@arg COLOR: --color "Show colored output") | ||
) | ||
.get_matches(); | ||
|
||
let log_recorder = utils::set_args(&args); | ||
match log_recorder { | ||
Ok(log_recorder) => Ok(log_recorder), | ||
Err(log_recorder) => Err(log_recorder), | ||
} | ||
} |
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 |
---|---|---|
@@ -1,40 +1,7 @@ | ||
use crate::kube; | ||
use clap::ArgMatches; | ||
use std::io::{Error, ErrorKind}; | ||
|
||
/// Parse the cli args, and return the kube::LogRecorderConfig | ||
pub fn set_args( | ||
args: &ArgMatches, | ||
) -> Result<kube::LogRecorderConfig, Box<dyn ::std::error::Error>> { | ||
let namespace = args.value_of("NAMESPACE").unwrap().to_string(); | ||
let kube_config = if let Some(kube_config) = args.value_of("KUBECONFIG") { | ||
kube_config | ||
} else { | ||
"" | ||
}; | ||
|
||
let mut outfile = ""; | ||
let file = args.is_present("FILE"); | ||
if file { | ||
outfile = if let Some(o) = args.value_of("OUTFILE") { | ||
o | ||
} else { | ||
"/tmp/wufei/" | ||
} | ||
} | ||
|
||
let color = args.is_present("COLOR"); | ||
Ok(kube::LogRecorderConfig::new( | ||
namespace.to_string(), | ||
kube_config.to_string(), | ||
file, | ||
color, | ||
outfile.to_string(), | ||
)) | ||
} | ||
|
||
/// Since Command returns stdout or stderr attrs instead of actual errors, we need a helper | ||
/// function to generate custom errors when dealing with Command. | ||
pub fn generate_err(err_msg: String) -> Result<(), Box<dyn ::std::error::Error>> { | ||
pub fn generate_err(err_msg: String) -> Result<(), Box<dyn::std::error::Error>> { | ||
Err(Box::new(Error::new(ErrorKind::Other, err_msg))) | ||
} |