CDD - Cli Driven Development

Still, self-isolation does not go unnoticed. You sit at home, and different thoughts come to mind. How to make humanity happy? And here it is: CDD! (And more PDD / SOLID / KISS / YAGNI / TDD / Bootstraping ...)





1.CDD - Cli Driven Development - New Approach

A bit of history

Somehow I was instructed to make Cli in one of our embedded devices. Of course, C / C ++ (let it be C ++, since there are enough resources). Of course there are many Cli frameworks out there.





But I made my own version.





Linux <termios.h> :





signal(SIGINT, SIGINT_Handler); // Ctrl+C
signal(SIGTSTP, SIGTSTP_Handler); // Ctrl+Z

int res_tcgetattr = tcgetattr(STDIN_FILENO, &terminal_state_prev);
terminal_state_new = terminal_state_prev;
terminal_state_new.c_lflag &= ~(ICANON | ECHO);
int res_tcsetattr = tcsetattr(STDIN_FILENO, TCSANOW, &terminal_state_new);
      
      



Windows <conio.h>.





, , :





{
 Cli_Command_Abstract_t *cmd = new Cli_Command_Abstract_t(Cli_Command_ID_help);
 cmd->Add(help_keyword);
 cmd->Help_Set("show this help, \"help full\" - show all available commands");
 command_tree->Add(cmd);
}
      
      



- , 10-20. help / quit / debug cli ( - ). , 20 , … SNMP / Syslog / NTP / Users / FTP / SSH / VLAN … - 250 . ! , , . CDD - Cli Driven Development.





1.1 Cli





, Cli, GUI, : , , , (Erlang, Lua .), IDE. , (, Paint : , VBA , ).





1.2 CDD





Cli- . Cisco-like - .





Cli? - :





  • , ;





  • ("");





  • ("");





  • ;





  • ;





  • ;





: debug cli - (CMD_ID / CMD_Item / CMD_Handler)





  • ID (" "), Realized- NotRealized- ; ( ID, Realized , NotRealized 0, : - 30...20...5...2 - ? ? - !)





1.3 CDD





CDD:





  1. - , Cli-, . Cli-.





  2. : .





  3. : ( , / / ).





1.4 mCli - CDD





CDD mCli - Cli- (github.com/MikeGM2017/mCli). , .





1.4.1 mCli





() Enter ( ) Ctrl+C ( ). Enter ( ), Ctrl+C ( ), Up/Down ( ), Left/Right/Home/End ( ), Back/Delete ( ).





1.4.2 mCli





mCli . :





  • Word / Word_List / Word_Range ( , List - , Range - )





  • Int / Int_List / Int_Range





  • Str





  • IP4 / IP6





  • MAC





  • Date / Time / DateTime





  • EQU_Range ( == != > < >= <= - , )





  • Rem ( - )





1.4.3 mCli





mCli , - .





:





  • Base_Quit ( )





  • Base_Help ( )





  • Base_Modules ( )





  • Base_History ( )





  • Base_Script ( )





  • Base_Rem (, )





  • Base_Wait (, )





  • Base_Log ( )





  • Base_Debug ( , )





  • Check ( , )





-

:





  • Output_printf (Linux/Window)





  • Output_cout (Linux/Window)





  • Output_ncurses (Linux)





  • Output_pdcurses (Linux/Window)





:





  • Input_termios (Linux)





  • Input_conio (Window)





  • Input_ncurses (Linux)





  • Input_pdcurses (Linux/Window)





:





  • ConfigureTerminal (: )





  • SecureTerminal (: )





  • TestTerminal (: )





1.5 mCli





, main():





Cli_Modules Modules;

// Modules Add - Begin

Modules.Add(new Cli_Module_Base_Rem(Str_Rem_DEF, Cli_Output));

bool Cmd_Quit = false;
Modules.Add(new Cli_Module_Base_Quit(Cmd_Quit));

Str_Filter str_filter('?', '*');
Modules.Add(new Cli_Module_Base_Help(User_Privilege, Modules, str_filter, Cli_Output));
Modules.Add(new Cli_Module_Base_Modules(User_Privilege, Modules, str_filter, Cli_Output));

Cli_History History;
Modules.Add(new Cli_Module_Base_History(History, Cli_Output));

Modules.Add(new Cli_Module_Base_Log(Cli_Input));

bool Cmd_Script_Stop = false;
int Script_Buf_Size = 1024;
Modules.Add(new Cli_Module_Base_Script(History, Cli_Output,
            Str_Rem_DEF, Cmd_Script_Stop, Cmd_Quit, Script_Buf_Size,
            CMD_Processor));

bool Log_Wait_Enable = true;
bool Cmd_Wait_Stop = false;
Modules.Add(new Cli_Module_Base_Wait(Log_Wait_Enable, Cmd_Wait_Stop, Cli_Input, Cli_Output));

Modules.Add(new Cli_Module_Test_Tab_Min_Max());
Modules.Add(new Cli_Module_Test_Terminal(Cli_Input, Cli_Output));

Modules.Add(new Cli_Module_Base_Debug(User_Privilege, Modules, Levels, CMD_Processor, Cli_Output));

Modules.Add(new Cli_Module_Check(Modules, Values_Map, str_filter, Cli_Output, Cmd_Script_Stop));

// Modules Add - End
      
      



1.6 CDD SOLID





SOLID CDD . - , Cli_Output . - (, Cli_Input , ).





, SOLID CDD - :





  • S -





  • O - : enum Local_CmdID, , Local_CmdID ? enum Local_CmdID () enum Local_CmdID , enum ( CMD_ID_LAST)





  • L - ,





  • I - , ( ) ; ( )





  • D -





1.7 CDD KISS





, : , , . , , … 2 !





. . , "help" "help full" , - "*". KISS :





  • , (, - , Cli ).





1.8 CDD DRY





, .





1.9 CDD YAGNI





- ? - ( ). .





1.10 CDD Bootstraping





(, Embedded Baremetal) . CDD " ".





1.11 CDD TDD





:





  • ;





  • ;





  • / ;





  • ;





1.12 CDD GUI





GUI? GUI ( Web - ) Cli - , , .





2. CDD PDD

PDD!!!





2.1 PDD - Provocation Driven Development - :)





, PDD - , . , , . ? , . , :





  • C ;





  • C++ - ( , : class MyCoolGame; myCoolGame.Run());





  • SQL, Lua - " ";





  • Assembler - " ";





  • Java - " ";





  • JavaScript - " , "; … - , , .





2.2 PDD CDD?





- . :





  • ? - .





  • ? - .





  • ? - .





  • ? - .





- , DSL. , "help".





:





  • Cli- 1 () -. , 1 10-20 Cli- (, ), : ( !) , 10 . 200-300 Cli- 200-300 - (, "", ).





, ( ) .





: , , , - , - "" .





Cli . , :





  • ;





  • ;





  • ;





  • Selection . , .





: , - , - .





-, CDD , CDD Waterfall, Agile. , , - Waterfall. Agile. CDD Waterfall, Agile, .





3.

3.1 Check





"Check".





, , : "check label " - "check if == goto " - ( : == != > < >= <= - , , )





- , map<string,string>, .To_Map().





, , . , , , - .





3.2 Check vs Lua





, Lua. , ( Check - 30 , ) Lua , . , Lua .





3.3 Check vs Erlang





, … Erlang . , "" , , Erlang .





4. CDD vs Erlang

, Erlang - CDD. , PDD Erlang? - " , ". , , . : "CDD Erlang" . CDD (C/C++, C#, Java, JavaScript). Erlang - . , Erlang vs CDD, Erlang + CDD ??? , ...





5. CDD

CDD-:





  • CDD- Base-;





  • legacy- Cli- "" "version get" / "info get" - " " ;





  • , : "start" / "stop" / "configure" …;





  • - / / . . - + ; ;





  • , 10-20 ;





  • , , , , . .





6.

CDD SOLID, KISS, DRY, YAGNI, Bootstraping, TDD.





CDD .





CDD .





CDD .





CDD .





CDD OS.





CDD . , .





CDD :





  • ;





  • ;





  • .





CDD , :





  • ;





  • .





CDD :





  • commands are parsed, data is validated, it is impossible to do anything outside Cli-commands (unless, of course, you enter commands like exec / system / eval).





CDD actually provides documentation on the functionality of the application:





  • it is enough to issue the command "help * verbose" - and the description of the commands and their arguments is already there.





Isn't that enough?





Then one last thing: CDD lets you take over the world. KMK ...





Yes, and Linux is worth rewriting over CDD. KMK








All Articles