Upgrading clap version to 4.x for skysh (#284)

next
Sanjay Sharma 2 years ago committed by GitHub
parent f41ea72747
commit 54d2075a6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

89
Cargo.lock generated

@ -254,13 +254,50 @@ dependencies = [
"ansi_term", "ansi_term",
"atty", "atty",
"bitflags", "bitflags",
"strsim", "strsim 0.8.0",
"textwrap", "textwrap",
"unicode-width", "unicode-width",
"vec_map", "vec_map",
"yaml-rust", "yaml-rust",
] ]
[[package]]
name = "clap"
version = "4.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06badb543e734a2d6568e19a40af66ed5364360b9226184926f89d229b4b4267"
dependencies = [
"atty",
"bitflags",
"clap_derive",
"clap_lex",
"once_cell",
"strsim 0.10.0",
"termcolor",
]
[[package]]
name = "clap_derive"
version = "4.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c42f169caba89a7d512b5418b09864543eeb4d497416c917d7137863bd2076ad"
dependencies = [
"heck",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8"
dependencies = [
"os_str_bytes",
]
[[package]] [[package]]
name = "clipboard-win" name = "clipboard-win"
version = "4.4.2" version = "4.4.2"
@ -594,6 +631,12 @@ dependencies = [
"ahash 0.7.6", "ahash 0.7.6",
] ]
[[package]]
name = "heck"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
[[package]] [[package]]
name = "hermit-abi" name = "hermit-abi"
version = "0.1.19" version = "0.1.19"
@ -906,6 +949,12 @@ dependencies = [
"vcpkg", "vcpkg",
] ]
[[package]]
name = "os_str_bytes"
version = "6.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff"
[[package]] [[package]]
name = "parking_lot" name = "parking_lot"
version = "0.12.1" version = "0.12.1"
@ -982,6 +1031,30 @@ version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
[[package]]
name = "proc-macro-error"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
dependencies = [
"proc-macro-error-attr",
"proc-macro2",
"quote",
"syn",
"version_check",
]
[[package]]
name = "proc-macro-error-attr"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
dependencies = [
"proc-macro2",
"quote",
"version_check",
]
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.46" version = "1.0.46"
@ -1268,7 +1341,7 @@ dependencies = [
name = "sky-bench" name = "sky-bench"
version = "0.8.0" version = "0.8.0"
dependencies = [ dependencies = [
"clap", "clap 2.34.0",
"devtimer", "devtimer",
"env_logger", "env_logger",
"libstress", "libstress",
@ -1284,7 +1357,7 @@ name = "sky-migrate"
version = "0.8.0" version = "0.8.0"
dependencies = [ dependencies = [
"bincode", "bincode",
"clap", "clap 2.34.0",
"env_logger", "env_logger",
"log", "log",
"skytable 0.8.0 (git+https://github.com/skytable/client-rust.git)", "skytable 0.8.0 (git+https://github.com/skytable/client-rust.git)",
@ -1310,7 +1383,7 @@ dependencies = [
"bytes", "bytes",
"cc", "cc",
"chrono", "chrono",
"clap", "clap 2.34.0",
"env_logger", "env_logger",
"hashbrown", "hashbrown",
"jemallocator", "jemallocator",
@ -1336,7 +1409,7 @@ dependencies = [
name = "skysh" name = "skysh"
version = "0.8.0" version = "0.8.0"
dependencies = [ dependencies = [
"clap", "clap 4.0.17",
"crossterm", "crossterm",
"lazy_static", "lazy_static",
"libsky", "libsky",
@ -1418,6 +1491,12 @@ version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]] [[package]]
name = "subtle" name = "subtle"
version = "2.4.1" version = "2.4.1"

@ -3,6 +3,7 @@ name = "skysh"
version = "0.8.0" version = "0.8.0"
authors = ["Sayan Nandan <ohsayan@outlook.com>"] authors = ["Sayan Nandan <ohsayan@outlook.com>"]
edition = "2021" edition = "2021"
description = "The Skytable Shell (skysh)"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -15,7 +16,7 @@ skytable = { git = "https://github.com/skytable/client-rust", branch = "next", f
], default-features = false } ], default-features = false }
# external deps # external deps
tokio = { version = "1.21.2", features = ["full"] } tokio = { version = "1.21.2", features = ["full"] }
clap = { version = "2", features = ["yaml"] } clap = { version = "4.0.15", features = ["derive"] }
rustyline = "10.0.0" rustyline = "10.0.0"
crossterm = "0.25.0" crossterm = "0.25.0"
lazy_static = "1.4.0" lazy_static = "1.4.0"

@ -1,9 +1,18 @@
# Skytable Shell # Skytable Shell
This directory contains the source code for the Skytable Shell. When compiled, it produces a single binary `skysh`, short for **Sky**table **s**hell. The Skytable shell can be used to connect to a Skytable instance and it provides some nice to have shell features like history, terminal interactions and more. This directory contains the source code for the Skytable Shell. When compiled, it produces a single binary `skysh`, short for **Sky**table **s**hell. The Skytable shell can be used to connect to a Skytable instance, and it provides some nice to have shell features like history, terminal interactions and more.
By default, `skysh` connects to the `default:default` entity for an instance running on `127.0.0.1` (localhost) on port `2003`. You can change these connection settings use command-line parameters. By default, `skysh` connects to the `default:default` entity for an instance running on `127.0.0.1` (localhost) on port `2003`. You can change these connection settings use command-line parameters.
# Usage
The below terminal interactions show a few ways in which `skysh` can be used:
```shell
# Use skysh to run one-off expressions
skysh -e "SET x 100" "GET x"
```
## License ## License
All files in this directory are distributed under the [AGPL-3.0 License](../LICENSE). All files in this directory are distributed under the [AGPL-3.0 License](../LICENSE).

@ -24,9 +24,10 @@
* *
*/ */
use crate::cli::Cli;
use { use {
crate::{runner::Runner, tokenizer}, crate::{runner::Runner, tokenizer},
clap::{load_yaml, App}, clap::Parser,
crossterm::{ crossterm::{
cursor, execute, cursor, execute,
terminal::{Clear, ClearType}, terminal::{Clear, ClearType},
@ -37,7 +38,6 @@ use {
std::{io::stdout, process}, std::{io::stdout, process},
}; };
const ADDR: &str = "127.0.0.1";
const SKYSH_HISTORY_FILE: &str = ".sky_history"; const SKYSH_HISTORY_FILE: &str = ".sky_history";
const HELP_TEXT: &str = r#" const HELP_TEXT: &str = r#"
@ -100,16 +100,7 @@ pub async fn start_repl() {
}; };
} }
let cfg_layout = load_yaml!("./cli.yml"); let cli = Cli::parse();
let matches = App::from_yaml(cfg_layout).get_matches();
let host = libsky::option_unwrap_or!(matches.value_of("host"), ADDR);
let port = match matches.value_of("port") {
Some(p) => match p.parse::<u16>() {
Ok(p) => p,
Err(_) => fatal!("Invalid port"),
},
None => 2003,
};
let mut editor = match Editor::<()>::new() { let mut editor = match Editor::<()>::new() {
Ok(e) => e, Ok(e) => e,
Err(e) => fatal!("Editor init error: {}", e), Err(e) => fatal!("Editor init error: {}", e),
@ -123,9 +114,9 @@ pub async fn start_repl() {
), ),
rustyline::Cmd::Noop, rustyline::Cmd::Noop,
); );
let con = match matches.value_of("cert") { let con = match cli.ssl_cert {
Some(cert) => Runner::new_secure(host, port, cert).await, Some(cert) => Runner::new_secure(&cli.host, cli.port, &cert).await,
None => Runner::new_insecure(host, port).await, None => Runner::new_insecure(&cli.host, cli.port).await,
}; };
let mut runner = match con { let mut runner = match con {
Ok(c) => c, Ok(c) => c,
@ -143,10 +134,10 @@ pub async fn start_repl() {
}; };
} }
if let Some(eval_expr) = matches.values_of("eval") { if let Some(expressions) = cli.expressions {
for eval_expr in eval_expr { for eval_expr in expressions {
if !eval_expr.is_empty() { if !eval_expr.is_empty() {
runner.run_query(eval_expr).await; runner.run_query(&eval_expr).await;
} }
} }
process::exit(0x00); process::exit(0x00);

@ -0,0 +1,29 @@
use clap::Parser;
use clap::ArgAction;
const HELP_TEMPLATE: &'static str = r#"
{before-help}{name} {version}
{author-with-newline}{about-with-newline}
{usage-heading} {usage}
{all-args}{after-help}
"#;
#[derive(Parser)]
#[command(author, version, about, long_about=None, disable_help_flag=true, help_template=HELP_TEMPLATE)]
pub struct Cli {
#[arg(short = 'C', long = "sslcert", help="Sets the PEM certificate to use for SSL connections", value_name = "CERT")]
pub ssl_cert: Option<String>,
#[arg(short = 'e', long = "eval", help = "Run one or more expressions without REPL", value_name = "EXPRESSION", num_args=0..)]
pub expressions: Option<Vec<String>>,
#[arg(short, long, help = "Sets the remote host to connect to", default_value = "127.0.0.1", value_name = "HOST")]
pub host: String,
#[arg(short, long, help = "Sets the remote port to connect to", default_value_t = 2003, value_name = "PORT")]
pub port: u16,
#[arg(long, help="Print help information", action=ArgAction::Help)]
pub help: Option<bool>
}

@ -1,55 +0,0 @@
#
# Created on Tue Nov 03 2020
#
# This file is a part of Skytable
# Copyright (c) 2020, Sayan Nandan <ohsayan@outlook.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
#
name: Skytable Shell
version: 0.8.0
author: Sayan N. <ohsayan@outlook.com>
about: The Skytable Shell (skysh)
args:
- host:
short: h
required: false
long: host
value_name: host
help: Sets the remote host to connect to
takes_value: true
- port:
short: p
required: false
long: port
value_name: port
help: Sets the remote port to connect to
takes_value: true
- eval:
short: e
required: false
long: eval
multiple: true
value_name: expression
help: Run an expression without REPL
takes_value: true
- cert:
short: C
required: false
long: sslcert
value_name: cert
help: Sets the PEM certificate to use for SSL connections
takes_value: true

@ -30,8 +30,10 @@
#[macro_use] #[macro_use]
mod macros; mod macros;
mod argparse; mod argparse;
mod cli;
mod runner; mod runner;
mod tokenizer; mod tokenizer;
// tests // tests
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;

Loading…
Cancel
Save