Skip to content
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

Merged
merged 11 commits into from
May 29, 2024
Merged

READY : Allow to save nature order in commands & props #1325

merged 11 commits into from
May 29, 2024

Conversation

SRetip
Copy link
Contributor

@SRetip SRetip commented May 13, 2024

No description provided.

@SRetip SRetip changed the title NOT READY: Allow to save nature order NOT READY: Allow to save nature order in commands & props May 13, 2024
@SRetip SRetip changed the title NOT READY: Allow to save nature order in commands & props READY: Allow to save nature order in commands & props May 13, 2024
@SRetip SRetip marked this pull request as ready for review May 13, 2024 10:56
@Wandalen Wandalen changed the title READY: Allow to save nature order in commands & props NOT REVIEWED: Allow to save nature order in commands & props May 13, 2024
@Wandalen
Copy link
Owner

@Barsik-sus review please

@Wandalen
Copy link
Owner

@Barsik-sus review please

Copy link
Contributor

@Barsik-sus Barsik-sus left a 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?

@@ -117,7 +117,7 @@ pub( crate ) mod private

#[ former( default = Verifier ) ]
verifier : Verifier,

Copy link
Contributor

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 >,
///
Copy link
Contributor

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

@@ -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 > >,
Copy link
Contributor

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

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let full_properties = if o.with_nature_order
let full_properties = if o.with_nature_order

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" )
Copy link
Contributor

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?

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" )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you fmt this?

{
// debug_assert!( dictionary.commands.len() == order.as_ref().map( | o | o.len() ).unwrap_or( dictionary.commands.len() ) );
Copy link
Contributor

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 ]
Copy link
Contributor

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

Copy link
Contributor

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

@Wandalen Wandalen changed the title NOT REVIEWED: Allow to save nature order in commands & props NOT READY : Allow to save nature order in commands & props May 27, 2024
@SRetip SRetip changed the title NOT READY : Allow to save nature order in commands & props READY : Allow to save nature order in commands & props May 27, 2024
@SRetip SRetip requested a review from Barsik-sus May 27, 2024 08:35
@@ -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 > > ) ]
Copy link
Contributor

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?

@SRetip SRetip requested a review from Barsik-sus May 27, 2024 17:17
@SRetip SRetip changed the title READY : Allow to save nature order in commands & props WAITING FOR REVIEW : Allow to save nature order in commands & props May 27, 2024
Copy link
Contributor

@Barsik-sus Barsik-sus left a 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

@@ -3,6 +3,7 @@ pub( crate ) mod private

use crate::*;
use wtools::Itertools;
use crate::ca::aggregator::private::Order;
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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

@@ -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;
Copy link
Contributor

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;
Copy link
Contributor

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() };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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() };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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() };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 )

};

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" );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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" );

@SRetip SRetip changed the title WAITING FOR REVIEW : Allow to save nature order in commands & props NOT READY : Allow to save nature order in commands & props May 28, 2024
@SRetip SRetip changed the title NOT READY : Allow to save nature order in commands & props READY : Allow to save nature order in commands & props May 28, 2024
@Wandalen Wandalen merged commit 4f18593 into Wandalen:alpha May 29, 2024
1 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants