Skip to content

Commit

Permalink
Merge pull request #47 from lucid-kv/fix-clap
Browse files Browse the repository at this point in the history
Improve CLAP/CLI
  • Loading branch information
Clint.Network committed Jan 19, 2020
2 parents 545aeb8 + 98353ce commit 198c44c
Show file tree
Hide file tree
Showing 7 changed files with 272 additions and 457 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ tree_magic = "*"
byte-unit = "*"
snafu = "*"
bytes = "*"
log = "*"
fern = "*"
tokio = "0.1.22"

Expand All @@ -53,3 +52,7 @@ features = ["yaml"]
[dependencies.warp]
version = "*"
features = ["tls"]

[dependencies.log]
version = "*"
features = ["serde"]
158 changes: 45 additions & 113 deletions src/cli.yml
Original file line number Diff line number Diff line change
@@ -1,117 +1,49 @@
name: Lucid
author: 'Written in Rust by Clint.Network (twitter.com/clint_network)'
name: "Lucid"
author: &author "Written in Rust by Clint.Network (https://github.com/lucid-kv)"
template: &template |-4
██╗ ██╗ ██╗ ██████╗██╗██████╗ ██╗ ██╗██╗ ██╗
██║ ██║ ██║██╔════╝██║██╔══██╗ ██║ ██╔╝██║ ██║
██║ ██║ ██║██║ ██║██║ ██║ ██╔═██╗ ╚██╗ ██╔╝
██████╗╚██████╔╝╚██████╗██║██████╔╝ ██║ ██╗ ╚████╔╝
╚═════╝ ╚═════╝ ╚═════╝╚═╝╚═════╝ ╚═╝ ╚═╝ ╚═══╝

A Fast, Secure and Distributed KV store with an HTTP API.
Written in Rust by Clint.Network (twitter.com/clint_network)

{all-args}
settings:
- "GlobalVersion"
- "SubcommandRequiredElseHelp"
args:
- config:
help: "Specify the Lucid configuration file"
short: "c"
long: "config"
takes_value: true
- no-banner:
help: "Disable showing the banner on start"
long: "no-banner"
subcommands:
-
cli:
about: 'Spawn to the command line interface'
author: 'Written in Rust by Clint.Network (twitter.com/clint_network)'
args:
-
help:
help: 'Prints CLI help information'
short: h
long: help
-
init:
about: 'Initialize Lucid and generate configuration file'
author: 'Written in Rust by Clint.Network (twitter.com/clint_network)'
- init:
about: "Initialize Lucid and generate configuration file"
author: *author
template: *template
args:
-
secret:
help: 'Set the JWT secret'
short: s
long: secret
- secret:
help: "Set the JWT secret"
short: "s"
long: "secret"
takes_value: true
-
force:
help: 'Initialize Lucid and overwrite existing configuration file'
short: f
long: force
- force:
help: "Initialize Lucid and overwrite existing configuration file"
short: "f"
long: "force"
takes_value: false
-
config:
help: 'Specify the Lucid configuration file location'
short: c
long: config
takes_value: true
-
server:
about: 'Run a new Lucid server instance'
author: 'Written in Rust by Clint.Network (twitter.com/clint_network)'
args:
-
config:
help: 'Specify the Lucid configuration file'
short: c
long: config
takes_value: true
-
settings:
about: 'Manage Lucid configuration file'
author: 'Written in Rust by Clint.Network (twitter.com/clint_network)'
subcommands:
- set:
about: 'Update a setting parameter'
author: 'Written in Rust by Clint.Network (twitter.com/clint_network)'
- get:
about: 'Get a setting parameter'
author: 'Written in Rust by Clint.Network (twitter.com/clint_network)'
args:
- config:
help: 'Specify the Lucid configuration file'
short: c
long: config
takes_value: true
-
store:
about: 'Play with the KV store (get/set)'
author: 'Written in Rust by Clint.Network (twitter.com/clint_network)'
-
tokens:
about: 'Manage JWT Tokens (issue, revoke etc.)'
author: 'Written in Rust by Clint.Network (twitter.com/clint_network)'
subcommands:
-
revoke:
about: 'Revoke a JWT Token'
author: 'Written in Rust by Clint.Network (twitter.com/clint_network)'
args:
-
token:
help: 'Token to revoke'
index: 1
-
issue:
about: 'Issue a new JWT Token'
author: 'Written in Rust by Clint.Network (twitter.com/clint_network)'
args:
-
expiration:
help: 'Specify the expiration date of the JWT Token (timestamp)'
short: e
long: expiration
takes_value: true
- count:
help: 'Number of tokens to issue '
short: c
long: count
index: 1
args:
- config:
help: 'Specify the Lucid configuration file'
short: c
long: config
takes_value: true
args:
-
help:
help: 'Prints help information'
short: h
long: help
takes_value: false
-
version:
help: 'Prints version information'
short: v
long: version
takes_value: false
- server:
about: "Run a new Lucid server instance"
author: *author
template: *template
- settings:
about: "Manage the Lucid configuration file"
author: *author
template: *template
44 changes: 27 additions & 17 deletions src/configuration.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
use std::net::{Ipv4Addr, IpAddr};
use std::{
net::{IpAddr, Ipv4Addr},
path::PathBuf,
};

use app_dirs::{AppDataType, AppDirsError};
use log::LevelFilter;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Configuration {
Expand All @@ -9,19 +15,27 @@ pub struct Configuration {
pub webui: WebUI,
pub store: Store,
pub http: Http,
pub logging: Logging
pub logging: Logging,
}

impl Configuration {
pub fn default() -> Configuration {
pub fn get_path() -> Result<PathBuf, AppDirsError> {
let mut path = app_dirs::get_app_root(AppDataType::UserConfig, &crate::APP_INFO)?;
path.push("lucid.yml");
Ok(path)
}
}

impl Default for Configuration {
fn default() -> Configuration {
Configuration {
general: General {
bind_address: IpAddr::from(Ipv4Addr::LOCALHOST),
port: 7020,
port_ssl: 7021,
use_ssl: true,
ssl_certificate: String::new(),
ssl_certificate_key: String::new()
ssl_certificate_key: String::new(),
},
authentication: Authentication {
enabled: true,
Expand All @@ -36,17 +50,13 @@ impl Configuration {
enabled: false,
private_key: String::new(),
},
webui: WebUI {
enabled: false
},
store: Store {
max_limit: 7340032
},
webui: WebUI { enabled: false },
store: Store { max_limit: 7340032 },
http: Http {
request_size_limit: 8388608
request_size_limit: 8388608,
},
logging: Logging {
level: "Info".to_string()
level: LevelFilter::Info,
},
}
}
Expand Down Expand Up @@ -83,22 +93,22 @@ pub struct Encryption {

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WebUI {
pub enabled: bool
pub enabled: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Store {
pub max_limit: u64
pub max_limit: u64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Http {
pub request_size_limit: u64
pub request_size_limit: u64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Logging {
pub level: String
pub level: LevelFilter,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand All @@ -107,4 +117,4 @@ pub struct Claims {
pub iss: String,
pub iat: i64,
pub exp: i64,
}
}
Loading

0 comments on commit 198c44c

Please sign in to comment.