@@ -2734,6 +2734,9 @@ def do_alias(self, args: argparse.Namespace) -> None:
27342734 " alias create save_results print_results \" >\" out.txt\n " )
27352735
27362736 alias_create_parser = DEFAULT_ARGUMENT_PARSER (description = alias_create_description , epilog = alias_create_epilog )
2737+ alias_create_parser .add_argument ('-s' , '--silent' , action = 'store_true' ,
2738+ help = 'do not print message confirming alias was created or\n '
2739+ 'overwritten' )
27372740 alias_create_parser .add_argument ('name' , help = 'name of this alias' )
27382741 alias_create_parser .add_argument ('command' , help = 'what the alias resolves to' ,
27392742 choices_method = _get_commands_aliases_and_macros_for_completion )
@@ -2743,7 +2746,6 @@ def do_alias(self, args: argparse.Namespace) -> None:
27432746 @as_subcommand_to ('alias' , 'create' , alias_create_parser , help = alias_create_description .lower ())
27442747 def _alias_create (self , args : argparse .Namespace ) -> None :
27452748 """Create or overwrite an alias"""
2746-
27472749 # Validate the alias name
27482750 valid , errmsg = self .statement_parser .is_valid_command (args .name )
27492751 if not valid :
@@ -2769,18 +2771,20 @@ def _alias_create(self, args: argparse.Namespace) -> None:
27692771 value += ' ' + ' ' .join (args .command_args )
27702772
27712773 # Set the alias
2772- result = "overwritten" if args .name in self .aliases else "created"
2774+ if not args .silent :
2775+ result = "overwritten" if args .name in self .aliases else "created"
2776+ self .poutput ("Alias '{}' {}" .format (args .name , result ))
2777+
27732778 self .aliases [args .name ] = value
2774- self .poutput ("Alias '{}' {}" .format (args .name , result ))
27752779
27762780 # alias -> delete
27772781 alias_delete_help = "delete aliases"
27782782 alias_delete_description = "Delete specified aliases or all aliases if --all is used"
27792783
27802784 alias_delete_parser = DEFAULT_ARGUMENT_PARSER (description = alias_delete_description )
2785+ alias_delete_parser .add_argument ('-a' , '--all' , action = 'store_true' , help = "delete all aliases" )
27812786 alias_delete_parser .add_argument ('names' , nargs = argparse .ZERO_OR_MORE , help = 'alias(es) to delete' ,
27822787 choices_method = _get_alias_completion_items , descriptive_header = 'Value' )
2783- alias_delete_parser .add_argument ('-a' , '--all' , action = 'store_true' , help = "delete all aliases" )
27842788
27852789 @as_subcommand_to ('alias' , 'delete' , alias_delete_parser , help = alias_delete_help )
27862790 def _alias_delete (self , args : argparse .Namespace ) -> None :
@@ -2806,21 +2810,29 @@ def _alias_delete(self, args: argparse.Namespace) -> None:
28062810 "Without arguments, all aliases will be listed." )
28072811
28082812 alias_list_parser = DEFAULT_ARGUMENT_PARSER (description = alias_list_description )
2813+ alias_list_parser .add_argument ('-w' , '--with_silent' , action = 'store_true' ,
2814+ help = "include --silent flag with listed aliases\n "
2815+ "Use this option when saving to a startup script that\n "
2816+ "should silently create aliases." )
28092817 alias_list_parser .add_argument ('names' , nargs = argparse .ZERO_OR_MORE , help = 'alias(es) to list' ,
28102818 choices_method = _get_alias_completion_items , descriptive_header = 'Value' )
28112819
28122820 @as_subcommand_to ('alias' , 'list' , alias_list_parser , help = alias_delete_help )
28132821 def _alias_list (self , args : argparse .Namespace ) -> None :
28142822 """List some or all aliases"""
2823+ create_cmd = "alias create"
2824+ if args .with_silent :
2825+ create_cmd += " --silent"
2826+
28152827 if args .names :
28162828 for cur_name in utils .remove_duplicates (args .names ):
28172829 if cur_name in self .aliases :
2818- self .poutput ("alias create {} {}" .format (cur_name , self .aliases [cur_name ]))
2830+ self .poutput ("{} {} {}" .format (create_cmd , cur_name , self .aliases [cur_name ]))
28192831 else :
28202832 self .perror ("Alias '{}' not found" .format (cur_name ))
28212833 else :
28222834 for cur_alias in sorted (self .aliases , key = self .default_sort_key ):
2823- self .poutput ("alias create {} {}" .format (cur_alias , self .aliases [cur_alias ]))
2835+ self .poutput ("{} {} {}" .format (create_cmd , cur_alias , self .aliases [cur_alias ]))
28242836
28252837 #############################################################
28262838 # Parsers and functions for macro command and subcommands
@@ -2884,6 +2896,9 @@ def do_macro(self, args: argparse.Namespace) -> None:
28842896 " will only complete paths while typing a macro." )
28852897
28862898 macro_create_parser = DEFAULT_ARGUMENT_PARSER (description = macro_create_description , epilog = macro_create_epilog )
2899+ macro_create_parser .add_argument ('-s' , '--silent' , action = 'store_true' ,
2900+ help = 'do not print message confirming macro was created or\n '
2901+ 'overwritten' )
28872902 macro_create_parser .add_argument ('name' , help = 'name of this macro' )
28882903 macro_create_parser .add_argument ('command' , help = 'what the macro resolves to' ,
28892904 choices_method = _get_commands_aliases_and_macros_for_completion )
@@ -2893,7 +2908,6 @@ def do_macro(self, args: argparse.Namespace) -> None:
28932908 @as_subcommand_to ('macro' , 'create' , macro_create_parser , help = macro_create_help )
28942909 def _macro_create (self , args : argparse .Namespace ) -> None :
28952910 """Create or overwrite a macro"""
2896-
28972911 # Validate the macro name
28982912 valid , errmsg = self .statement_parser .is_valid_command (args .name )
28992913 if not valid :
@@ -2966,17 +2980,19 @@ def _macro_create(self, args: argparse.Namespace) -> None:
29662980 break
29672981
29682982 # Set the macro
2969- result = "overwritten" if args .name in self .macros else "created"
2983+ if not args .silent :
2984+ result = "overwritten" if args .name in self .macros else "created"
2985+ self .poutput ("Macro '{}' {}" .format (args .name , result ))
2986+
29702987 self .macros [args .name ] = Macro (name = args .name , value = value , minimum_arg_count = max_arg_num , arg_list = arg_list )
2971- self .poutput ("Macro '{}' {}" .format (args .name , result ))
29722988
29732989 # macro -> delete
29742990 macro_delete_help = "delete macros"
29752991 macro_delete_description = "Delete specified macros or all macros if --all is used"
29762992 macro_delete_parser = DEFAULT_ARGUMENT_PARSER (description = macro_delete_description )
2993+ macro_delete_parser .add_argument ('-a' , '--all' , action = 'store_true' , help = "delete all macros" )
29772994 macro_delete_parser .add_argument ('names' , nargs = argparse .ZERO_OR_MORE , help = 'macro(s) to delete' ,
29782995 choices_method = _get_macro_completion_items , descriptive_header = 'Value' )
2979- macro_delete_parser .add_argument ('-a' , '--all' , action = 'store_true' , help = "delete all macros" )
29802996
29812997 @as_subcommand_to ('macro' , 'delete' , macro_delete_parser , help = macro_delete_help )
29822998 def _macro_delete (self , args : argparse .Namespace ) -> None :
@@ -3002,21 +3018,29 @@ def _macro_delete(self, args: argparse.Namespace) -> None:
30023018 "Without arguments, all macros will be listed." )
30033019
30043020 macro_list_parser = DEFAULT_ARGUMENT_PARSER (description = macro_list_description )
3021+ macro_list_parser .add_argument ('-w' , '--with_silent' , action = 'store_true' ,
3022+ help = "include --silent flag with listed macros\n "
3023+ "Use this option when saving to a startup script that\n "
3024+ "should silently create macros." )
30053025 macro_list_parser .add_argument ('names' , nargs = argparse .ZERO_OR_MORE , help = 'macro(s) to list' ,
30063026 choices_method = _get_macro_completion_items , descriptive_header = 'Value' )
30073027
30083028 @as_subcommand_to ('macro' , 'list' , macro_list_parser , help = macro_list_help )
30093029 def _macro_list (self , args : argparse .Namespace ) -> None :
30103030 """List some or all macros"""
3031+ create_cmd = "macro create"
3032+ if args .with_silent :
3033+ create_cmd += " --silent"
3034+
30113035 if args .names :
30123036 for cur_name in utils .remove_duplicates (args .names ):
30133037 if cur_name in self .macros :
3014- self .poutput ("macro create {} {}" .format (cur_name , self .macros [cur_name ].value ))
3038+ self .poutput ("{} {} {}" .format (create_cmd , cur_name , self .macros [cur_name ].value ))
30153039 else :
30163040 self .perror ("Macro '{}' not found" .format (cur_name ))
30173041 else :
30183042 for cur_macro in sorted (self .macros , key = self .default_sort_key ):
3019- self .poutput ("macro create {} {}" .format (cur_macro , self .macros [cur_macro ].value ))
3043+ self .poutput ("{} {} {}" .format (create_cmd , cur_macro , self .macros [cur_macro ].value ))
30203044
30213045 def complete_help_command (self , text : str , line : str , begidx : int , endidx : int ) -> List [str ]:
30223046 """Completes the command argument of help"""
@@ -3051,12 +3075,12 @@ def complete_help_subcommands(self, text: str, line: str, begidx: int, endidx: i
30513075
30523076 help_parser = DEFAULT_ARGUMENT_PARSER (description = "List available commands or provide "
30533077 "detailed help for a specific command" )
3078+ help_parser .add_argument ('-v' , '--verbose' , action = 'store_true' ,
3079+ help = "print a list of all commands with descriptions of each" )
30543080 help_parser .add_argument ('command' , nargs = argparse .OPTIONAL , help = "command to retrieve help for" ,
30553081 completer_method = complete_help_command )
30563082 help_parser .add_argument ('subcommands' , nargs = argparse .REMAINDER , help = "subcommand(s) to retrieve help for" ,
30573083 completer_method = complete_help_subcommands )
3058- help_parser .add_argument ('-v' , '--verbose' , action = 'store_true' ,
3059- help = "print a list of all commands with descriptions of each" )
30603084
30613085 # Get rid of cmd's complete_help() functions so ArgparseCompleter will complete the help command
30623086 if getattr (cmd .Cmd , 'complete_help' , None ) is not None :
0 commit comments