Skip to content

Commit

Permalink
WCA: Improve hints and update sample
Browse files Browse the repository at this point in the history
If no hint is given, use the long hint and vice versa
  • Loading branch information
Barsik-sus committed Mar 20, 2023
1 parent b2ec3b0 commit 8707d1f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions module/move/wca/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ path = "rust/test/ca/wca_tests.rs"
name = "wca_smoke_test"
path = "rust/test/_integration_test/smoke_test.rs"

# [[example]]
# name = "wca_trivial_sample"
# path = "sample/rust/wca_trivial_sample/src/main.rs"
[[example]]
name = "wca_trivial_sample"
path = "sample/rust/wca_trivial_sample/src/main.rs"

[dependencies]
wtools = { version = "~0.2", path = "../../rust/wtools" }
Expand Down
14 changes: 7 additions & 7 deletions rust/impl/ca/ca/commands_aggregator/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub( crate ) mod private
if let Some( command ) = command
{
let name = &command.phrase;
let hint = &command.long_hint;
let hint = if command.long_hint.is_empty() { &command.hint } else { &command.long_hint };
let subjects = command.subjects.iter().enumerate().fold( String::new(), | acc, ( number, subj ) | format!( "{acc} <subject_{number}:{:?}>", subj.kind ) );
let full_subjects = command.subjects.iter().enumerate().map( |( number, subj )| format!( "subject_{number} - {} [{:?}]", subj.hint, subj.kind ) ).join( "\n\t\t" );
let properties = if command.properties.is_empty() { " " } else { " <properties> " };
Expand All @@ -36,7 +36,9 @@ pub( crate ) mod private
{
let subjects = cmd.subjects.iter().fold( String::new(), | acc, subj | format!( "{acc} <{:?}>", subj.kind ) );
let properties = if cmd.properties.is_empty() { " " } else { " <properties> " };
format!( "{acc}\n{name}{subjects}{properties}- {}", cmd.hint )
let hint = if cmd.hint.is_empty() { &cmd.long_hint } else { &cmd.hint };

format!( "{acc}\n{name}{subjects}{properties}- {hint}" )
})
})
.fold( String::new(), | acc, cmd |
Expand Down Expand Up @@ -85,8 +87,7 @@ pub( crate ) mod private
let phrase = "help".to_string();

let help = Command::former()
.hint( "hint" )
.long_hint( "long_hint" )
.hint( "prints information about existing commands" )
.phrase( &phrase )
.form();

Expand Down Expand Up @@ -121,8 +122,7 @@ pub( crate ) mod private

// generate and add grammar of help command
let help = Command::former()
.hint( "help" )
.long_hint( "" )
.hint( "prints full information about a specified command" )
.phrase( &phrase )
.subject( "command name", Type::String )
.form();
Expand Down Expand Up @@ -175,7 +175,7 @@ pub( crate ) mod private
// generate Commands grammar
let grammar_helps = commands
.iter()
.map( |( help_name, _ )| Command::former().hint( "help" ).long_hint( "" ).phrase( help_name ).form() )
.map( |( help_name, _ )| Command::former().hint( "prints full information about a specified command" ).phrase( help_name ).form() )
.collect::< Vec< _ > >();

// add commands to GrammarConverter
Expand Down
4 changes: 2 additions & 2 deletions sample/rust/wca_trivial_sample/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ fn main()
[
Command::former()
.phrase( "echo" )
.hint( "prints all subjects and properties" )
.subject( "Subject", Type::String )
.property( "property", "simple property", Type::String )
.form(),
Expand All @@ -21,8 +22,7 @@ fn main()
Ok( () )
})),
])
.with_help_command()
.form();
.build();

let args = std::env::args().skip( 1 ).collect::< Vec< String > >();
ca.perform( args.join( " " ) ).unwrap();
Expand Down

0 comments on commit 8707d1f

Please sign in to comment.