-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
READY : Allow to save nature order in commands & props #1325
Conversation
@Barsik-sus review please |
@Barsik-sus review please |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does with_nature_sort
work for both command and property order, or only for one of them?
module/move/wca/src/ca/aggregator.rs
Outdated
@@ -117,7 +117,7 @@ pub( crate ) mod private | |||
|
|||
#[ former( default = Verifier ) ] | |||
verifier : Verifier, | |||
|
|||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
@@ -100,6 +99,8 @@ pub( crate ) mod private | |||
pub subjects : Vec< ValueDescription >, | |||
/// Hints and types for command options. | |||
pub properties : HashMap< String, ValueDescription >, | |||
/// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you write concise documentation
module/move/wca/src/ca/help.rs
Outdated
@@ -53,6 +53,11 @@ pub( crate ) mod private | |||
pub description_detailing : LevelOfDetail, | |||
/// If enabled - shows complete description of subjects and properties | |||
pub with_footer : bool, | |||
|
|||
order : Option< Vec< String > >, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you write concise documentation
module/move/wca/src/ca/help.rs
Outdated
LevelOfDetail::Detailed => command.properties.iter().map( |( n, v )| format!( "< {n}:{}{:?} >", if v.optional { "?" } else { "" }, v.kind ) ).collect::< Vec< _ > >().join( " " ), | ||
}; | ||
|
||
let footer = if o.with_footer | ||
{ | ||
let full_subjects = command.subjects.iter().map( | subj | format!( "- {} [{}{:?}]", subj.hint, if subj.optional { "?" } else { "" }, subj.kind ) ).join( "\n\t" ); | ||
let full_properties = format_table( command.properties.iter().sorted_by_key( |( name, _ )| *name ).map( |( name, value )| [ name.clone(), format!( "- {} [{}{:?}]", value.hint, if value.optional { "?" } else { "" }, value.kind ) ] ) ).unwrap().replace( '\n', "\n\t" ); | ||
let full_properties = if o.with_nature_order |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let full_properties = if o.with_nature_order | |
let full_properties = if o.with_nature_order |
module/move/wca/src/ca/help.rs
Outdated
let full_properties = format_table( command.properties.iter().sorted_by_key( |( name, _ )| *name ).map( |( name, value )| [ name.clone(), format!( "- {} [{}{:?}]", value.hint, if value.optional { "?" } else { "" }, value.kind ) ] ) ).unwrap().replace( '\n', "\n\t" ); | ||
let full_properties = if o.with_nature_order | ||
{ | ||
format_table( command.properties_order.iter().map( | name | [ name.clone(), format!( "- {} [{}{:?}]", command.properties.get( name ).unwrap().hint, if command.properties.get( name ).unwrap().optional { "?" } else { "" }, command.properties.get( name ).unwrap().kind ) ] ) ).unwrap().replace( '\n', "\n\t" ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can avoid duplication here, can't we?
module/move/wca/src/ca/help.rs
Outdated
let full_properties = format_table( command.properties.iter().sorted_by_key( |( name, _ )| *name ).map( |( name, value )| [ name.clone(), format!( "- {} [{}{:?}]", value.hint, if value.optional { "?" } else { "" }, value.kind ) ] ) ).unwrap().replace( '\n', "\n\t" ); | ||
let full_properties = if o.with_nature_order | ||
{ | ||
format_table( command.properties_order.iter().map( | name | [ name.clone(), format!( "- {} [{}{:?}]", command.properties.get( name ).unwrap().hint, if command.properties.get( name ).unwrap().optional { "?" } else { "" }, command.properties.get( name ).unwrap().kind ) ] ) ).unwrap().replace( '\n', "\n\t" ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you fmt this?
module/move/wca/src/ca/help.rs
Outdated
{ | ||
// debug_assert!( dictionary.commands.len() == order.as_ref().map( | o | o.len() ).unwrap_or( dictionary.commands.len() ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove redundant comments, please
@@ -59,3 +59,76 @@ wca = {{path = "{}"}}"#, | |||
result | |||
); | |||
} | |||
|
|||
#[ test ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think It would be better if we refactor these tests to be able to see what the input is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not what I meant. Now we have to support this comment as well, and that's bad. I mean, we can modify the test to create the crate at the arrangement stage of a test
module/move/wca/src/ca/aggregator.rs
Outdated
@@ -100,7 +100,7 @@ pub( crate ) mod private | |||
/// ``` | |||
#[ derive( Debug ) ] | |||
#[ derive( former::Former ) ] | |||
#[ storage_fields( help_generator : HelpGeneratorFn, help_variants : HashSet< HelpVariants > ) ] | |||
#[ storage_fields( help_generator : HelpGeneratorFn, help_variants : HashSet< HelpVariants >, with_nature_sort : bool, order : Option< Vec< String > > ) ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use enum
instead of bool
, can't we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my honest opinion, storing information about ordering in a dictionary is not the best idea, but if it works, I don't know how it would be better
module/move/wca/src/ca/formatter.rs
Outdated
@@ -3,6 +3,7 @@ pub( crate ) mod private | |||
|
|||
use crate::*; | |||
use wtools::Itertools; | |||
use crate::ca::aggregator::private::Order; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be not in line with the convention
use former::{ Former, StoragePreform }; | ||
use crate::ca::aggregator::private::Order; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be not in line with the convention
use former::Former; | ||
use crate::ca::aggregator::private::Order; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be not in line with the convention
module/move/wca/src/ca/help.rs
Outdated
@@ -12,6 +12,7 @@ pub( crate ) mod private | |||
use error_tools::for_app::anyhow; | |||
use former::Former; | |||
use ca::tool::table::format_table; | |||
use crate::ca::aggregator::private::Order; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be not in line with the convention
use wtools::{ error, error::Result, err }; | ||
use ca::help::private::{ HelpGeneratorOptions, LevelOfDetail, generate_help_content }; | ||
use crate::ca::grammar::dictionary::private::CommandName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be not in line with the convention
let value = ValueDescription | ||
{ | ||
hint : property.hint, | ||
kind : property.kind, | ||
optional : property.optional, | ||
}; | ||
debug_assert!( !properties.contains_key( &property.name ), "Property name `{}` is already used for `{:?}`", property.name, properties[ &property.name ] ); | ||
properties.insert( property.name.clone(), value ); | ||
super_former.storage.last_id = Some( super_former.storage.last_id.unwrap_or_default() + 1 ); | ||
let name = CommandName{ id : super_former.storage.last_id.unwrap(), name : property.name.clone() }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let name = CommandName{ id : super_former.storage.last_id.unwrap(), name : property.name.clone() }; | |
let name = CommandName { id : super_former.storage.last_id.unwrap(), name : property.name.clone() }; |
@@ -31,7 +85,9 @@ pub( crate ) mod private | |||
pub fn command( mut self, command : Command ) -> Self | |||
{ | |||
let mut commands = self.storage.commands.unwrap_or_default(); | |||
commands.extend([( command.phrase.clone(), command )]); | |||
self.storage.dictionary_last_id = Some( self.storage.dictionary_last_id.unwrap_or_default() + 1 ); | |||
let name = CommandName{ id : self.storage.dictionary_last_id.unwrap(), name : command.phrase.clone() }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let name = CommandName{ id : self.storage.dictionary_last_id.unwrap(), name : command.phrase.clone() }; | |
let name = CommandName { id : self.storage.dictionary_last_id.unwrap(), name : command.phrase.clone() }; |
@@ -47,7 +103,9 @@ pub( crate ) mod private | |||
/// * `command` - The command to be registered. | |||
pub fn register( &mut self, command : Command ) -> Option< Command > | |||
{ | |||
self.commands.insert( command.phrase.clone(), command ) | |||
self.dictionary_last_id += 1; | |||
let name = CommandName{ id : self.dictionary_last_id, name : command.phrase.clone() }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let name = CommandName{ id : self.dictionary_last_id, name : command.phrase.clone() }; | |
let name = CommandName { id : self.dictionary_last_id, name : command.phrase.clone() }; |
{ | ||
self.commands.get( name ) | ||
self.commands.iter().find( |(k, _)| k.name == name.to_string() ).map(|(_, v)| v) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.commands.iter().find( |(k, _)| k.name == name.to_string() ).map(|(_, v)| v) | |
self.commands.iter().find( |( k, _ )| k.name == name.to_string() ).map( |( _, v )| v ) |
module/move/wca/src/ca/help.rs
Outdated
}; | ||
|
||
let footer = if o.with_footer | ||
{ | ||
let full_subjects = command.subjects.iter().map( | subj | format!( "- {} [{}{:?}]", subj.hint, if subj.optional { "?" } else { "" }, subj.kind ) ).join( "\n\t" ); | ||
let full_properties = format_table( command.properties.iter().sorted_by_key( |( name, _ )| *name ).map( |( name, value )| [ name.clone(), format!( "- {} [{}{:?}]", value.hint, if value.optional { "?" } else { "" }, value.kind ) ] ) ).unwrap().replace( '\n', "\n\t" ); | ||
let full_properties = format_table( command.properties( dictionary.order ).into_iter().map( | ( name, value ) | [ name.clone(), format!( "- {} [{}{:?}]", value.hint, if value.optional { "?" } else { "" }, value.kind ) ] )).unwrap().replace( '\n', "\n\t" ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let full_properties = format_table( command.properties( dictionary.order ).into_iter().map( | ( name, value ) | [ name.clone(), format!( "- {} [{}{:?}]", value.hint, if value.optional { "?" } else { "" }, value.kind ) ] )).unwrap().replace( '\n', "\n\t" ); | |
let full_properties = format_table( command.properties( dictionary.order ).into_iter().map( | ( name, value ) | [ name.clone(), format!( "- {} [{}{:?}]", value.hint, if value.optional { "?" } else { "" }, value.kind ) ] ) ).unwrap().replace( '\n', "\n\t" ); |
No description provided.