Skip to content

Commit

Permalink
feat: added openapi-path to cli args, removed other args
Browse files Browse the repository at this point in the history
  • Loading branch information
zaghaghi committed Mar 2, 2024
1 parent 134797d commit ca20d8d
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
.data/*.log
.vscode/
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "openapi-tui"
version = "0.1.0"
edition = "2021"
description = "View and try APIs with an openapi file"
description = "Terminal UI to list, browse and run APIs defined with openapi spec."

authors = ["Hamed Zaghaghi <hamed.zaghaghi@gmail.com>"]
build = "build.rs"
Expand Down
14 changes: 6 additions & 8 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ use tokio::sync::mpsc;

use crate::{
action::Action,
components::{home::Home, fps::FpsCounter, Component},
components::{fps::FpsCounter, home::Home, Component},
config::Config,
mode::Mode,
tui,
};

pub struct App {
pub config: Config,
pub tick_rate: f64,
pub frame_rate: f64,
pub openapi_path: String,
pub components: Vec<Box<dyn Component>>,
pub should_quit: bool,
pub should_suspend: bool,
Expand All @@ -24,27 +23,26 @@ pub struct App {
}

impl App {
pub fn new(tick_rate: f64, frame_rate: f64) -> Result<Self> {
pub fn new(openapi_path: String) -> Result<Self> {
let home = Home::new();
let fps = FpsCounter::default();
let config = Config::new()?;
let mode = Mode::Home;
Ok(Self {
tick_rate,
frame_rate,
components: vec![Box::new(home), Box::new(fps)],
should_quit: false,
should_suspend: false,
config,
mode,
openapi_path,
last_tick_key_events: Vec::new(),
})
}

pub async fn run(&mut self) -> Result<()> {
let (action_tx, mut action_rx) = mpsc::unbounded_channel();

let mut tui = tui::Tui::new()?.tick_rate(self.tick_rate).frame_rate(self.frame_rate);
let mut tui = tui::Tui::new()?;
// tui.mouse(true);
tui.enter()?;

Expand Down Expand Up @@ -137,7 +135,7 @@ impl App {
if self.should_suspend {
tui.suspend()?;
action_tx.send(Action::Resume)?;
tui = tui::Tui::new()?.tick_rate(self.tick_rate).frame_rate(self.frame_rate);
tui = tui::Tui::new()?;
// tui.mouse(true);
tui.enter()?;
} else if self.should_quit {
Expand Down
11 changes: 4 additions & 7 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@ use crate::utils::version;
#[derive(Parser, Debug)]
#[command(author, version = version(), about)]
pub struct Cli {
#[arg(short, long, value_name = "FLOAT", help = "Tick rate, i.e. number of ticks per second", default_value_t = 1.0)]
pub tick_rate: f64,

#[arg(
short,
long,
value_name = "FLOAT",
help = "Frame rate, i.e. number of frames per second",
default_value_t = 4.0
value_name = "PATH",
help = "Input file, i.e. json or yaml file with openapi specification",
default_value_t= String::from("openapi.json")
)]
pub frame_rate: f64,
pub openapi_path: String,
}
4 changes: 1 addition & 3 deletions src/components/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ impl Component for Home {

fn update(&mut self, action: Action) -> Result<Option<Action>> {
match action {
Action::Tick => {
},
Action::Tick => {},
_ => {},
}
Ok(None)
Expand All @@ -49,4 +48,3 @@ impl Component for Home {
Ok(())
}
}

13 changes: 4 additions & 9 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
use std::{collections::HashMap, fmt, path::PathBuf};
use std::{collections::HashMap, path::PathBuf};

use color_eyre::eyre::Result;
use config::Value;
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use derive_deref::{Deref, DerefMut};
use ratatui::style::{Color, Modifier, Style};
use serde::{
de::{self, Deserializer, MapAccess, Visitor},
Deserialize, Serialize,
};
use serde_json::Value as JsonValue;
use serde::{de::Deserializer, Deserialize};

use crate::{action::Action, mode::Mode};

Expand Down Expand Up @@ -201,7 +196,7 @@ pub fn key_event_to_string(key_event: &KeyEvent) -> String {
char = format!("f({c})");
&char
},
KeyCode::Char(c) if c == ' ' => "space",
KeyCode::Char(' ') => "space",
KeyCode::Char(c) => {
char = c.to_string();
&char
Expand Down Expand Up @@ -429,7 +424,7 @@ mod tests {
#[test]
fn test_parse_color_rgb() {
let color = parse_color("rgb123");
let expected = 16 + 1 * 36 + 2 * 6 + 3;
let expected = 16 + 36 + 2 * 6 + 3;
assert_eq!(color, Some(Color::Indexed(expected)));
}

Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use color_eyre::eyre::Result;

use crate::{
app::App,
utils::{initialize_logging, initialize_panic_handler, version},
utils::{initialize_logging, initialize_panic_handler},
};

async fn tokio_main() -> Result<()> {
Expand All @@ -26,7 +26,7 @@ async fn tokio_main() -> Result<()> {
initialize_panic_handler()?;

let args = Cli::parse();
let mut app = App::new(args.tick_rate, args.frame_rate)?;
let mut app = App::new(args.openapi_path)?;
app.run().await?;

Ok(())
Expand Down

0 comments on commit ca20d8d

Please sign in to comment.