|
|
@ -6,68 +6,92 @@ pub struct CLI { |
|
|
|
pub datasource_url: String, |
|
|
|
pub datasource_url: String, |
|
|
|
pub query: String, |
|
|
|
pub query: String, |
|
|
|
pub from: u64, |
|
|
|
pub from: u64, |
|
|
|
pub to: u64 |
|
|
|
pub to: u64, |
|
|
|
|
|
|
|
pub step: u64, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl CLI { |
|
|
|
impl CLI { |
|
|
|
|
|
|
|
|
|
|
|
pub fn new() -> CLI { |
|
|
|
pub fn new() -> CLI { |
|
|
|
|
|
|
|
|
|
|
|
let matches = App::new("subbeat") |
|
|
|
let matches = App::new("subbeat") |
|
|
|
.version("0.0.2") |
|
|
|
.version("0.0.2") |
|
|
|
.about("Timeseries toolkit") |
|
|
|
.about("Timeseries toolkit") |
|
|
|
.arg( |
|
|
|
.subcommand( |
|
|
|
Arg::with_name("GRAFANA_URL") |
|
|
|
SubCommand::with_name("grafana") |
|
|
|
.help("URL to your Grafana instance") |
|
|
|
.about("Use Grafana as datasource") |
|
|
|
.required(true) |
|
|
|
.arg( |
|
|
|
.index(1), |
|
|
|
Arg::with_name("GRAFANA_URL") |
|
|
|
) |
|
|
|
.help("URL to your Grafana instance") |
|
|
|
.arg( |
|
|
|
.required(true) |
|
|
|
Arg::with_name("GRAFANA_API_KEY") |
|
|
|
.index(1), |
|
|
|
.help("Grafna API Key. Go to http://<grafana-url>/org/apikeys to get one") |
|
|
|
) |
|
|
|
.required(true) |
|
|
|
.arg( |
|
|
|
.index(2), |
|
|
|
Arg::with_name("GRAFANA_API_KEY") |
|
|
|
) |
|
|
|
.help( |
|
|
|
.arg( |
|
|
|
"Grafna API Key. Go to http://<grafana-url>/org/apikeys to get one", |
|
|
|
Arg::with_name("datasource_url") |
|
|
|
) |
|
|
|
.help("relative path to datasource") |
|
|
|
.required(true) |
|
|
|
.required(true) |
|
|
|
.index(2), |
|
|
|
.index(3), |
|
|
|
) |
|
|
|
) |
|
|
|
.arg( |
|
|
|
.arg( |
|
|
|
Arg::with_name("datasource_url") |
|
|
|
Arg::with_name("query") |
|
|
|
.help("relative path to datasource") |
|
|
|
.help("your query to datasource") |
|
|
|
.required(true) |
|
|
|
.required(true) |
|
|
|
.index(3), |
|
|
|
.index(4), |
|
|
|
) |
|
|
|
) |
|
|
|
.arg( |
|
|
|
.arg( |
|
|
|
Arg::with_name("query") |
|
|
|
Arg::with_name("from") |
|
|
|
.help("your query to datasource") |
|
|
|
.help("timestamp") |
|
|
|
.required(true) |
|
|
|
.required(true) |
|
|
|
.index(4), |
|
|
|
.index(5), |
|
|
|
) |
|
|
|
) |
|
|
|
.arg( |
|
|
|
.arg( |
|
|
|
Arg::with_name("from") |
|
|
|
Arg::with_name("to") |
|
|
|
.help("timestamp") |
|
|
|
.help("timestampt") |
|
|
|
.required(true) |
|
|
|
.required(true) |
|
|
|
.index(5), |
|
|
|
.index(6), |
|
|
|
) |
|
|
|
|
|
|
|
.arg( |
|
|
|
|
|
|
|
Arg::with_name("to") |
|
|
|
|
|
|
|
.help("timestampt") |
|
|
|
|
|
|
|
.required(true) |
|
|
|
|
|
|
|
.index(6), |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.arg( |
|
|
|
|
|
|
|
Arg::with_name("step") |
|
|
|
|
|
|
|
.help("aggregation step") |
|
|
|
|
|
|
|
.required(true) |
|
|
|
|
|
|
|
.index(7), |
|
|
|
|
|
|
|
), |
|
|
|
) |
|
|
|
) |
|
|
|
.get_matches(); |
|
|
|
.get_matches(); |
|
|
|
|
|
|
|
|
|
|
|
let url = matches.value_of("GRAFANA_URL").unwrap(); |
|
|
|
if let Some(matches) = matches.subcommand_matches("grafana") { |
|
|
|
let key = matches.value_of("GRAFANA_API_KEY").unwrap(); |
|
|
|
let url = matches.value_of("GRAFANA_URL").unwrap(); |
|
|
|
let datasource_url = matches.value_of("datasource_url").unwrap(); |
|
|
|
let key = matches.value_of("GRAFANA_API_KEY").unwrap(); |
|
|
|
let query = matches.value_of("query").unwrap(); |
|
|
|
let datasource_url = matches.value_of("datasource_url").unwrap(); |
|
|
|
let from = matches.value_of("from").unwrap().parse().unwrap(); |
|
|
|
let query = matches.value_of("query").unwrap(); |
|
|
|
let to = matches.value_of("to").unwrap().parse().unwrap(); |
|
|
|
let from = matches.value_of("from").unwrap().parse().unwrap(); |
|
|
|
|
|
|
|
let to = matches.value_of("to").unwrap().parse().unwrap(); |
|
|
|
CLI{ |
|
|
|
let step = matches.value_of("step").unwrap().parse().unwrap(); |
|
|
|
url: url.to_owned(), |
|
|
|
return CLI { |
|
|
|
key: key.to_owned(), |
|
|
|
url: url.to_owned(), |
|
|
|
datasource_url: datasource_url.to_owned(), |
|
|
|
key: key.to_owned(), |
|
|
|
query: query.to_owned(), |
|
|
|
datasource_url: datasource_url.to_owned(), |
|
|
|
from, |
|
|
|
query: query.to_owned(), |
|
|
|
to |
|
|
|
from, |
|
|
|
|
|
|
|
to, |
|
|
|
|
|
|
|
step, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return CLI { |
|
|
|
|
|
|
|
url: "url.to_owned()".to_string(), |
|
|
|
|
|
|
|
key: "key.to_owned()".to_string(), |
|
|
|
|
|
|
|
datasource_url: "datasource_url.to_owned()".to_string(), |
|
|
|
|
|
|
|
query: "query.to_owned()".to_string(), |
|
|
|
|
|
|
|
from: 0, |
|
|
|
|
|
|
|
to: 0, |
|
|
|
|
|
|
|
step: 0, |
|
|
|
|
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |