Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Commit

Permalink
refactor: Major rework of curl commands (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
PThorpe92 authored Sep 30, 2023
1 parent 515a853 commit 73e76d6
Show file tree
Hide file tree
Showing 7 changed files with 367 additions and 531 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
# Rust TUI HTTP Client with API Key Management


Terminal user interface (TUI) HTTP client in Rust designed to simplify the process of making various types of HTTP requests while supporting various different kinds of Authentication (powered by cURL), recursive downloading of files (powered by WGET), and storage management of your API keys.
Terminal user interface (TUI) HTTP client in Rust designed to simplify the process of making various types of HTTP requests while supporting various different kinds of Authentication (powered by libcURL), recursive downloading of files (powered by WGET), and storage + management of your API keys.

Have you ever wanted to just grab some data from an API, or demonstrate that your REST endpoint is working, and had to craft some 2 paragraph long curl CLI command, just to forget every flag and option you used the next time you need to do it?
Have you ever wanted to just grab some data from an API, or demonstrate that your REST endpoint is working, and had to craft some 2 paragraph long curl CLI command, just to forget every flag and option you used the next time you need to do send the same command?

Now, not only can you execute these commands from a simple TUI and either view the response or write it to a file, but _CuTE_ will build the actual curl command string you need to run it again, should you wish to share it with someone else, use it on a server, or just keep it for later.
Now, not only can you execute these commands from a simple TUI and either view the response or write it to a file, but on top of executing the command with libcurl, _CuTE_ will build the actual curl command string you need to run it again, should you wish to share it with someone else, use it on a server, or just keep it stashed for later.

## Features

- **Interactive TUI Interface**: The application offers an intuitive TUI interface that makes it easy to construct and execute HTTP requests without leaving the terminal.

- **Intuitive VIM keybindings:** Navigate the TUI using the familiar Vim keybindings you know and love.

- **Multiple Request Types**: With this tool, you can effortlessly create and send all the standard HTTP request types, and even use multiple forms of Authentication, without knowing an entire sub-language known as `curl-cli-flags`. This ensures flexibility in your interaction with different APIs.

- **API Key Management**: The project includes a simple-to-use API key management system. You can store your API keys within the application and assign them names for easy reference.
Expand All @@ -30,7 +32,7 @@ Now, not only can you execute these commands from a simple TUI and either view t

## Why don't you support `X`?

- See above `why`: Supporting every available action in libcurl would be a monumental task. If there are enough requests for a specific feature, it will be considered. Otherwise, PR's are welcome.
- See above `why`: Supporting every available action or authentication type in libcurl would be a monumental task. If there are enough requests for a specific feature, it will be considered. Otherwise, PR's are welcome.


## Installation
Expand Down
16 changes: 8 additions & 8 deletions src/display/shareablecmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,34 +61,34 @@ impl ShareableCommand {
}

// Whitespace
command_str.push_str(" ");
command_str.push(' ');
// URL
command_str.push_str(&self.url);

// Next We Check For Headers
if self.headers.len() > 0 {
if !self.headers.is_empty() {
for (key, value) in &self.headers {
// Whitespace
command_str.push_str("");
// Header Flag
command_str.push_str("-H ");
// Open Quote
command_str.push_str("\"");
command_str.push('\"');
// Header Key
command_str.push_str(&key);
command_str.push_str(key);
// Delimiter
command_str.push_str(":");
command_str.push(':');
// Header Value
command_str.push_str(&value);
command_str.push_str(value);
// Close Quote
command_str.push_str("\"");
command_str.push('\"');
}
}

// Check For Outfile
if !self.outfile.is_empty() {
// Whitespace
command_str.push_str(" ");
command_str.push(' ');
// Outfile Flag
command_str.push_str(" -o ");
// Outfile Name
Expand Down
8 changes: 5 additions & 3 deletions src/events/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use tui_input::InputRequest;

use crate::app::InputMode;
use crate::app::{App, AppResult};
use crate::screens::screen::Screen;

/// Handles the key events and updates the state of [`App`].
pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
Expand All @@ -11,8 +12,7 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
match key_event.kind {
KeyEventKind::Press => {
match key_event.code {
// Exit application on `ESC` or `q`
KeyCode::Esc | KeyCode::Char('q') => {
KeyCode::Char('q') => {
app.quit();
}
// Exit application on `Ctrl-C`
Expand All @@ -32,7 +32,9 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
app.select_item();
}
KeyCode::Char('i') => {
app.input_mode = InputMode::Editing;
if let Screen::InputMenu(_) = app.current_screen {
app.input_mode = InputMode::Editing;
}
}
KeyCode::Char('j') => {
app.move_cursor_down();
Expand Down
46 changes: 23 additions & 23 deletions src/request/command.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::request::curl::{Curl, CurlFlag};
use crate::request::wget::Wget;

use super::curl::AuthKind;
use super::curl::{AuthKind, CurlFlagType};

#[derive(Debug)]
pub enum Command<'a> {
Expand Down Expand Up @@ -41,9 +41,8 @@ impl<'a> Command<'a> {
}
}
pub fn add_download_auth(&mut self, user: &str, pwd: &str) {
match self {
Command::Wget(wget) => wget.add_auth(user, pwd),
_ => {}
if let Command::Wget(wget) = self {
wget.add_auth(user, pwd)
}
}

Expand All @@ -61,7 +60,10 @@ impl<'a> Command<'a> {
pub fn set_outfile(&mut self, file: &str) {
match self {
Command::Curl(curl) => {
curl.add_flag(CurlFlag::Output(""), Some(String::from(file)));
curl.add_flag(CurlFlag::Output(
CurlFlagType::Output.get_value(),
Some(String::from(file)),
));
}
Command::Wget(wget) => {
wget.set_output(file);
Expand All @@ -70,11 +72,8 @@ impl<'a> Command<'a> {
}

pub fn set_headers(&mut self, headers: Vec<String>) {
match self {
Command::Curl(curl) => {
curl.add_headers(headers);
}
_ => {}
if let Command::Curl(curl) = self {
curl.add_headers(headers);
}
}

Expand Down Expand Up @@ -103,23 +102,27 @@ impl<'a> Command<'a> {
}

pub fn set_verbose(&mut self, verbose: bool) {
match self {
Command::Curl(curl) => curl.set_verbose(verbose),
_ => {}
if let Command::Curl(curl) = self {
curl.set_verbose(verbose);
}
}

pub fn execute(&mut self) -> Result<(), std::io::Error> {
match self {
Command::Curl(curl) => Ok(curl.execute().unwrap()),
Command::Wget(wget) => Ok(wget.execute().unwrap()),
Command::Curl(curl) => {
curl.execute().unwrap();
Ok(())
}
Command::Wget(wget) => {
wget.execute().unwrap();
Ok(())
}
}
}

pub fn set_rec_download_level(&mut self, level: usize) {
match self {
Command::Wget(wget) => wget.set_rec_download_level(level),
_ => {}
if let Command::Wget(wget) = self {
wget.set_rec_download_level(level);
}
}

Expand All @@ -134,11 +137,8 @@ impl<'a> Command<'a> {
}

pub fn set_response(&mut self, response: &str) {
match self {
Command::Curl(curl) => {
curl.set_response(response);
}
_ => {}
if let Command::Curl(curl) = self {
curl.set_response(response);
}
}

Expand Down
Loading

0 comments on commit 73e76d6

Please sign in to comment.