Skip to content

Commit

Permalink
Merge branch 'main' into diralik/remove-genesis-network
Browse files Browse the repository at this point in the history
  • Loading branch information
dima74 authored Jun 6, 2024
2 parents af0571f + 97aeb13 commit 2702fb6
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 75 deletions.
21 changes: 11 additions & 10 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ serde_yaml = "0.9.34"
serde_with = { version = "3.8.1", default-features = false }
parity-scale-codec = { version = "3.6.12", default-features = false }
json5 = "0.4.1"
toml = "0.8.13"
toml = "0.8.14"

storage = { git = "https://github.com/Erigara/storage.git", rev = "6bd9fdd95220da7626471d190b17b2f5b8815c47" }

Expand Down
8 changes: 4 additions & 4 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -774,12 +774,12 @@ fn validate_try_bind_address(emitter: &mut Emitter<ConfigError>, value: &WithOri
}

#[allow(missing_docs)]
pub fn is_colouring_supported() -> bool {
pub fn is_coloring_supported() -> bool {
supports_color::on(supports_color::Stream::Stdout).is_some()
}

fn default_terminal_colors_str() -> clap::builder::OsStr {
is_colouring_supported().to_string().into()
is_coloring_supported().to_string().into()
}

/// Iroha server CLI
Expand Down Expand Up @@ -1001,7 +1001,7 @@ mod tests {
fn default_args() {
let args = Args::try_parse_from(["test"]).unwrap();

assert_eq!(args.terminal_colors, is_colouring_supported());
assert_eq!(args.terminal_colors, is_coloring_supported());
assert_eq!(args.submit_genesis, false);
}

Expand All @@ -1014,7 +1014,7 @@ mod tests {

assert_eq!(
Args::try_parse_from(["test"])?.terminal_colors,
is_colouring_supported()
is_coloring_supported()
);
assert_eq!(try_with("--terminal-colors")?, true);
assert_eq!(try_with("--terminal-colors=false")?, false);
Expand Down
78 changes: 39 additions & 39 deletions client_cli/pytests/poetry.lock

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

Binary file modified configs/swarm/executor.wasm
Binary file not shown.
11 changes: 8 additions & 3 deletions data_model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -868,9 +868,7 @@ mod model {
/// String containing serialized valid JSON.
///
/// This string is guaranteed to be parsed as JSON.
#[derive(
Display, Default, Debug, Clone, Encode, Decode, Ord, PartialOrd, Eq, PartialEq, IntoSchema,
)]
#[derive(Display, Debug, Clone, Encode, Decode, Ord, PartialOrd, Eq, PartialEq, IntoSchema)]
#[ffi_type(unsafe {robust})]
#[repr(transparent)]
#[display(fmt = "{}", "0")]
Expand Down Expand Up @@ -906,6 +904,13 @@ impl JsonString {
}
}

impl Default for JsonString {
fn default() -> Self {
// NOTE: empty string isn't valid JSON
Self("null".to_string())
}
}

impl From<&serde_json::Value> for JsonString {
fn from(value: &serde_json::Value) -> Self {
Self(value.to_string())
Expand Down
8 changes: 2 additions & 6 deletions tools/parity_scale_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ license.workspace = true
[lints]
workspace = true

[features]
# Disable colour for all program output.
# Useful for Docker-based deployment and terminals without colour support.
no_color = ["colored/no-color"]

[dependencies]
iroha_data_model = { workspace = true, features = ["http"] }
iroha_primitives = { workspace = true }
Expand All @@ -24,12 +19,13 @@ iroha_crypto = { workspace = true }
iroha_version = { workspace = true }
iroha_genesis = { workspace = true }

clap = { workspace = true, features = ["derive", "cargo"] }
clap = { workspace = true, features = ["derive", "cargo", "env", "string"] }
eyre = { workspace = true }
parity-scale-codec = { workspace = true }
colored = "2.1.0"
serde_json = { workspace = true, features = ["std"]}
serde = { workspace = true }
supports-color = { workspace = true }

[build-dependencies]
iroha_data_model = { workspace = true }
Expand Down
6 changes: 0 additions & 6 deletions tools/parity_scale_cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ To build the tool, run:
cargo build --bin parity_scale_cli
```

If your terminal does not support colours, run:

```bash
cargo build --features no_color --bin parity_scale_cli
```

## Usage

Run Parity Scale Decoder Tool:
Expand Down
61 changes: 55 additions & 6 deletions tools/parity_scale_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,29 @@ where
/// Parity Scale decoder tool for Iroha data types
#[derive(Debug, Parser)]
#[clap(version, about, author)]
enum Args {
struct Args {
#[clap(subcommand)]
command: Command,

/// Whether to enable ANSI colored output or not
///
/// By default, Iroha determines whether the terminal supports colors or not.
///
/// In order to disable this flag explicitly, pass `--terminal-colors=false`.
#[arg(
long,
env,
default_missing_value("true"),
default_value(default_terminal_colors_str()),
action(clap::ArgAction::Set),
require_equals(true),
num_args(0..=1),
)]
pub terminal_colors: bool,
}

#[derive(Debug, Parser)]
enum Command {
/// Show all available types
ListTypes,
/// Decode SCALE to Rust debug format from binary file
Expand Down Expand Up @@ -113,26 +135,34 @@ struct ScaleJsonArgs {
type_name: String,
}

fn is_coloring_supported() -> bool {
supports_color::on(supports_color::Stream::Stdout).is_some()
}

fn default_terminal_colors_str() -> clap::builder::OsStr {
is_coloring_supported().to_string().into()
}

fn main() -> Result<()> {
let args = Args::parse();

let map = generate_map();

match args {
Args::ScaleToRust(decode_args) => {
match args.command {
Command::ScaleToRust(decode_args) => {
let mut writer = BufWriter::new(io::stdout().lock());
let decoder = ScaleToRustDecoder::new(decode_args, &map);
decoder.decode(&mut writer)
}
Args::ScaleToJson(args) => {
Command::ScaleToJson(args) => {
let decoder = ScaleJsonDecoder::new(args, &map)?;
decoder.scale_to_json()
}
Args::JsonToScale(args) => {
Command::JsonToScale(args) => {
let decoder = ScaleJsonDecoder::new(args, &map)?;
decoder.json_to_scale()
}
Args::ListTypes => {
Command::ListTypes => {
let mut writer = BufWriter::new(io::stdout().lock());
list_types(&map, &mut writer)
}
Expand Down Expand Up @@ -383,4 +413,23 @@ mod tests {
.expect("Couldn't convert to SCALE");
assert_eq!(scale_actual, scale_expected);
}

#[test]
fn terminal_colors_works_as_expected() -> eyre::Result<()> {
fn try_with(arg: &str) -> eyre::Result<bool> {
// Since arg contains enum Command and we must provide something for it, we use "list-types"
Ok(Args::try_parse_from(["test", arg, "list-types"])?.terminal_colors)
}

assert_eq!(
Args::try_parse_from(["test", "list-types"])?.terminal_colors,
is_coloring_supported()
);
assert_eq!(try_with("--terminal-colors")?, true);
assert_eq!(try_with("--terminal-colors=false")?, false);
assert_eq!(try_with("--terminal-colors=true")?, true);
assert!(try_with("--terminal-colors=random").is_err());

Ok(())
}
}

0 comments on commit 2702fb6

Please sign in to comment.