Skip to content

Commit

Permalink
Refactor CommandsAggregator and related tests
Browse files Browse the repository at this point in the history
The CommandsAggregator's interface and associated tests have been heavily refactored. Changes include the removal of extraneous code, updating subject handling in commands, and implementing cleaner command definition in tests. These changes streamline the workflow when working with the CommandsAggregator and improve code readability.
  • Loading branch information
Barsik-sus committed Mar 11, 2024
1 parent 4be8d56 commit 867fdf2
Show file tree
Hide file tree
Showing 16 changed files with 312 additions and 456 deletions.
36 changes: 18 additions & 18 deletions module/move/wca/examples/wca_shortcut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@
//! ```
//!

use wca::CommandExt;

/// Example of a command.
fn echo( () : (), args : wca::Args, _props : wca::Props ) -> Result< (), () >
{
let mut args = args.0.into_iter();
wca::parse_args!( args, value: String );

println!( "{value}" );

Ok( () )
}
// use wca::CommandExt;
//
// /// Example of a command.
// fn echo( () : (), args : wca::Args, _props : wca::Props ) -> Result< (), () >
// {
// let mut args = args.0.into_iter();
// wca::parse_args!( args, value: String );
//
// println!( "{value}" );
//
// Ok( () )
// }

/// Entry point.
fn main()
{
let args = std::env::args().skip( 1 ).collect::< Vec< _ > >().join( " " );
let aggregator = wca::cui( () )
.command( echo.arg( "string", wca::Type::String ) )
.build()
;
aggregator.perform( args ).unwrap();
// let args = std::env::args().skip( 1 ).collect::< Vec< _ > >().join( " " );
// let aggregator = wca::cui( () )
// .command( echo.arg( "string", wca::Type::String ) )
// .build()
// ;
// aggregator.perform( args ).unwrap();
}
20 changes: 6 additions & 14 deletions module/move/wca/examples/wca_suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,21 @@
//! ```
//!

use wca::{ CommandsAggregator, Args, Props };

fn main()
{
// use wca::prelude::*;

let ca = wca::CommandsAggregator::former()
.grammar
([
wca::Command::former()
.phrase( "echo" )
let ca = CommandsAggregator::former()
.command( "echo" )
.hint( "prints all subjects and properties" )
.subject( "Subject", wca::Type::String, true )
.property( "property", "simple property", wca::Type::String, true )
.form(),
])
.executor
([
( "echo".to_owned(), wca::Routine::new( | ( args, props ) |
.routine( | args : Args, props : Props |
{
println!( "= Args\n{args:?}\n\n= Properties\n{props:?}\n" );
Ok( () )
})
),
])
.end()
.perform();

let args = std::env::args().skip( 1 ).collect::< Vec< String > >();
Expand Down
49 changes: 28 additions & 21 deletions module/move/wca/examples/wca_trivial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,35 @@
//! A trivial example.
//!

fn main()
use wca::{ CommandsAggregator, Args, Props, Type };

fn f1( args : Args, props : Props )
{
println!( "= Args\n{args:?}\n\n= Properties\n{props:?}\n" );
}

fn exit()
{
println!( "just exit" );

let ca = wca::CommandsAggregator::former()
.grammar
([
wca::Command::former()
.phrase( "echo" )
std::process::exit( 0 )
}

fn main()
{
let ca = CommandsAggregator::former()
.command( "echo" )
.hint( "prints all subjects and properties" )
.subject( "Subject", wca::Type::String, true )
.property( "property", "simple property", wca::Type::String, true )
.form(),
])
.executor
([
( "echo".to_owned(), wca::Routine::new( |( args, props )|
{
println!( "= Args\n{args:?}\n\n= Properties\n{props:?}\n" );
Ok( () )
})),
])
.perform();
.subject( "Subject", Type::String, true )
.property( "property", "simple property", Type::String, true )
.routine( f1 )
.end()
.command( "exit" )
.hint( "just exit" )
.routine( || exit() )
.end()
.perform()
;

// aaa : qqq2 : for Bohdan : that should work
// let ca = wca::CommandsAggregator::former()
Expand All @@ -42,6 +49,6 @@ fn main()
// ca.execute( input ).unwrap();
//aaa: works

let args = std::env::args().skip( 1 ).collect::< Vec< String > >();
ca.perform( args.join( " " ) ).unwrap();
let input = std::env::args().skip( 1 ).collect::< Vec< String > >();
ca.perform( input ).unwrap();
}
6 changes: 3 additions & 3 deletions module/move/wca/src/ca/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ pub( crate ) mod private
#[ perform( fn build() -> CommandsAggregator ) ]
pub struct CommandsAggregator
{
#[ setter( false ) ]
#[ default( Dictionary::default() ) ]
dictionary : Dictionary,

Expand Down Expand Up @@ -162,6 +161,7 @@ pub( crate ) mod private

impl CommandsAggregatorFormer
{
// qqq : delete on completion
// /// Setter for grammar
// ///
// /// Gets list of available commands
Expand Down Expand Up @@ -243,7 +243,7 @@ pub( crate ) mod private
/// Construct CommandsAggregator
fn build( self ) -> CommandsAggregator
{
let mut ca = self;
// let mut ca = self;

// if ca.help_variants.contains( &HelpVariants::All )
// {
Expand All @@ -259,7 +259,7 @@ pub( crate ) mod private
//
// dot_command( &mut ca.dictionary );

ca
self
}

/// Parse, converts and executes a program
Expand Down
3 changes: 2 additions & 1 deletion module/move/wca/src/ca/verifier/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub( crate ) mod private
use crate::*;

use ca::grammar::command::ValueDescription;
use former::Former;
// use former::Former;
use std::collections::HashMap;
use wtools::{ error, error::Result, err };

Expand Down Expand Up @@ -40,6 +40,7 @@ pub( crate ) mod private
#[ derive( Debug, Clone ) ]
// #[ derive( Former ) ]
pub struct Verifier;
// qqq : delete on completion
// {
// // TODO: Make getters
// /// all available commands
Expand Down
7 changes: 4 additions & 3 deletions module/move/wca/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ use mod_interface::mod_interface;
/// Tools
pub mod wtools;

/// Errors.
#[ cfg( not( feature = "no_std" ) ) ]
use wtools::error::BasicError;
// qqq : maybe remove this?
// /// Errors.
// #[ cfg( not( feature = "no_std" ) ) ]
// use wtools::error::BasicError;
// xxx : check

crate::mod_interface!
Expand Down
Loading

0 comments on commit 867fdf2

Please sign in to comment.