Skip to content

Commit

Permalink
fix!: Return CliError from CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobsvante committed Nov 1, 2021
1 parent e2bf7d1 commit 5cbcbcb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/cli/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ pub enum CliError {
UnknownEnvironmentVariable(String),
#[error("Parameter format invalid")]
BadParam,
#[error("IO error: {0}")]
IOError(#[from] std::io::Error),
#[error("{0}")]
LibraryError(#[from] crate::error::Error),
}
15 changes: 5 additions & 10 deletions src/cli/main.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
use std::{
fs,
io::{stdout, Write},
net::SocketAddrV4,
os::unix::prelude::OsStrExt,
};
use std::{fs::{self, read_to_string}, io::{stdout, Write}, net::SocketAddrV4, os::unix::prelude::OsStrExt};

use clap::Parser;
use log::{debug, LevelFilter};

use super::opts::{Opts, RestApiSubCommand, SubCommand};
use super::{helpers::safe_extract_arg, ini};
use super::error::CliError;
use crate::config::Config;
use crate::error::Error;
use crate::rest_api::RestApi;

pub fn run() -> Result<(), Error> {
pub fn run() -> Result<(), CliError> {
if let Some(level_filter) = safe_extract_arg::<LevelFilter>("level-filter") {
env_logger::builder().filter(None, level_filter).init();
}
Expand Down Expand Up @@ -52,7 +47,7 @@ pub fn run() -> Result<(), Error> {
Ok(())
}

fn rest_api_sub_command(subcmd: RestApiSubCommand, api: RestApi) -> Result<(), Error> {
fn rest_api_sub_command(subcmd: RestApiSubCommand, api: RestApi) -> Result<(), CliError> {
use RestApiSubCommand::*;
match subcmd {
RestApiSubCommand::SuiteQl {
Expand Down Expand Up @@ -188,7 +183,7 @@ fn rest_api_sub_command(subcmd: RestApiSubCommand, api: RestApi) -> Result<(), E
Ok(())
}

fn openapi_serve(bind: SocketAddrV4, schema: &str) -> Result<(), Error> {
fn openapi_serve(bind: SocketAddrV4, schema: &str) -> Result<(), CliError> {
use tiny_http::{Header, Response, Server, StatusCode};
let server = Server::http(bind).unwrap();
for req in server.incoming_requests() {
Expand Down

0 comments on commit 5cbcbcb

Please sign in to comment.