Skip to content

Commit ee1e734

Browse files
committed
feat: added slot cmd
1 parent 9537ad3 commit ee1e734

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tinydancer/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "tinydancer"
3-
version = "0.0.7"
3+
version = "0.0.8"
44
edition = "2021"
55
default-run = "tinydancer"
66
authors = ["Anoushk Kharangate <[email protected]>"]

tinydancer/src/main.rs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ pub enum Commands {
9595
/// Edit your client config
9696
#[clap(subcommand)]
9797
Config(ConfigSubcommands),
98+
Slot,
9899
}
99100
#[derive(Debug, Subcommand)]
100101
pub enum ConfigSubcommands {
@@ -159,7 +160,41 @@ async fn main() {
159160
client.join().await;
160161
}
161162
Err(e) => {
162-
println!("error: {:?}", e);
163+
// println!("error: {:?}", e);
164+
std::process::Command::new("echo")
165+
.arg("\"Please set a config first using tindancer config set\"")
166+
.spawn()
167+
.expect("Config not set");
168+
}
169+
}
170+
}
171+
Commands::Slot => {
172+
let config_file = {
173+
let home_path = std::env::var("HOME").unwrap();
174+
175+
// println!("path {:?}", path);
176+
let text =
177+
std::fs::read_to_string(home_path + "/.config/tinydancer/config.json").unwrap();
178+
179+
serde_json::from_str::<ConfigSchema>(&text)
180+
};
181+
match config_file {
182+
Ok(config_file) => {
183+
let slot_res = send_rpc_call!(
184+
get_endpoint(config_file.cluster),
185+
serde_json::json!({"jsonrpc":"2.0","id":1, "method":"getSlot"}).to_string()
186+
);
187+
let slot = serde_json::from_str::<GetSlotResponse>(slot_res.as_str());
188+
match slot {
189+
Ok(slot) => {
190+
println!("Slot: {}", slot.result.to_string().green(),);
191+
}
192+
Err(e) => {
193+
println!("Failed to get slot,due to error: {}", e.to_string().red());
194+
}
195+
}
196+
}
197+
Err(_) => {
163198
std::process::Command::new("echo")
164199
.arg("\"Please set a config first using tindancer config set\"")
165200
.spawn()
@@ -325,3 +360,11 @@ pub struct ConfigSchema {
325360
pub log_path: String,
326361
pub cluster: String,
327362
}
363+
364+
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
365+
#[serde(rename_all = "camelCase")]
366+
pub struct GetSlotResponse {
367+
pub jsonrpc: String,
368+
pub result: i64,
369+
pub id: i64,
370+
}

0 commit comments

Comments
 (0)