Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 120 additions & 2 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hit-cli"
version = "0.5.1"
version = "0.6.0"
edition = "2021"
authors = ["Mehmood S. Deshmukh <meshde.md@gmail.com>"]
homepage = "https://usehit.dev"
Expand Down Expand Up @@ -29,7 +29,7 @@ hyper = "1.3.1"
inquire = "0.7.5"
openapiv3 = "1.0.1"
regex = "1.10.4"
reqwest = {version="0.12.3", features=["json"]}
reqwest = {version="0.12.3", features=["json", "multipart"]}
serde = {version="1.0.200", features=["derive"]}
serde_json = "1.0"
serde_yaml = "0.9"
Expand All @@ -40,5 +40,6 @@ tokio = {version = "1.37.0", features = ["full"]}
[dev-dependencies]
assert_cmd = "2.0.17"
insta = {version="1.43.1", features=["json"]}
mockito = "1.7"
predicates = "3.1.3"
rstest = "0.25.0"
3 changes: 2 additions & 1 deletion src/cli/env/use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ pub struct EnvUseArguments {
}

pub fn init(args: EnvUseArguments) -> Result<(), Box<dyn std::error::Error>> {
Ok(set_env(args.env))
set_env(args.env);
Ok(())
}
3 changes: 2 additions & 1 deletion src/cli/ephenv/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ pub struct EphenvSetArguments {
}

pub fn init(args: EphenvSetArguments) -> Result<(), Box<dyn std::error::Error>> {
Ok(set_ephenv(args.key, args.value))
set_ephenv(args.key, args.value);
Ok(())
}
57 changes: 27 additions & 30 deletions src/cli/last/view.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::core::app_config::get_app_config;
use crate::utils::input::CustomAutocomplete;
use arboard::Clipboard;
use colored_json;
use crossterm::event::{read, Event, KeyCode};
use crossterm::terminal;
use flatten_json_object::Flattener;
Expand All @@ -10,7 +9,7 @@ use serde_json::Value;
use std::io::stdout;
use std::io::Write;

fn get_json_value_from_path<'a, 'b>(json: &'a Value, path: &'b str) -> Option<&'a Value> {
fn get_json_value_from_path<'a>(json: &'a Value, path: &str) -> Option<&'a Value> {
json.pointer(format!("/{}", path.replace(".", "/")).as_str())
}

Expand All @@ -21,48 +20,46 @@ pub fn init() -> Result<(), Box<dyn std::error::Error>> {
.clone();

let mut prev_request = serde_json::to_value(prev_request).unwrap();
if let Ok(body_json) = serde_json::from_str::<Value>(&prev_request["body"].as_str().unwrap()) {
if let Ok(body_json) = serde_json::from_str::<Value>(prev_request["body"].as_str().unwrap()) {
prev_request["body"] = body_json;
}

let mut out = stdout();
colored_json::write_colored_json(&prev_request, &mut out).unwrap();
out.flush().unwrap();
writeln!(out, "").unwrap();
writeln!(out).unwrap();
println!("Press c to enter copy mode or any other key to exit");
terminal::enable_raw_mode().unwrap();

loop {
if let Ok(event) = read() {
if let Event::Key(key) = event {
terminal::disable_raw_mode().unwrap();
if key.code == KeyCode::Char('c') {
let flattened_json = Flattener::new().flatten(&prev_request).unwrap();
if let Ok(Event::Key(key)) = read() {
terminal::disable_raw_mode().unwrap();
if key.code == KeyCode::Char('c') {
let flattened_json = Flattener::new().flatten(&prev_request).unwrap();

let json_paths: Vec<String> = flattened_json
.as_object()
.unwrap()
.keys()
.map(|k| k.to_string())
.collect();
let json_paths: Vec<String> = flattened_json
.as_object()
.unwrap()
.keys()
.map(|k| k.to_string())
.collect();

let user_json_path = Text::new("Enter the JSON path: ")
.with_autocomplete(CustomAutocomplete::new(json_paths))
.prompt()
.unwrap();
Clipboard::new()
.unwrap()
.set_text(
get_json_value_from_path(&prev_request, &user_json_path)
.unwrap()
.to_string(),
)
.unwrap();
}
break;
let user_json_path = Text::new("Enter the JSON path: ")
.with_autocomplete(CustomAutocomplete::new(json_paths))
.prompt()
.unwrap();
Clipboard::new()
.unwrap()
.set_text(
get_json_value_from_path(&prev_request, &user_json_path)
.unwrap()
.to_string(),
)
.unwrap();
}
break;
}
}
println!("");
println!();
Ok(())
}
Loading
Loading