@@ -2734,6 +2734,9 @@ def do_alias(self, args: argparse.Namespace) -> None:
2734
2734
" alias create save_results print_results \" >\" out.txt\n " )
2735
2735
2736
2736
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' )
2737
2740
alias_create_parser .add_argument ('name' , help = 'name of this alias' )
2738
2741
alias_create_parser .add_argument ('command' , help = 'what the alias resolves to' ,
2739
2742
choices_method = _get_commands_aliases_and_macros_for_completion )
@@ -2743,7 +2746,6 @@ def do_alias(self, args: argparse.Namespace) -> None:
2743
2746
@as_subcommand_to ('alias' , 'create' , alias_create_parser , help = alias_create_description .lower ())
2744
2747
def _alias_create (self , args : argparse .Namespace ) -> None :
2745
2748
"""Create or overwrite an alias"""
2746
-
2747
2749
# Validate the alias name
2748
2750
valid , errmsg = self .statement_parser .is_valid_command (args .name )
2749
2751
if not valid :
@@ -2769,18 +2771,20 @@ def _alias_create(self, args: argparse.Namespace) -> None:
2769
2771
value += ' ' + ' ' .join (args .command_args )
2770
2772
2771
2773
# 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
+
2773
2778
self .aliases [args .name ] = value
2774
- self .poutput ("Alias '{}' {}" .format (args .name , result ))
2775
2779
2776
2780
# alias -> delete
2777
2781
alias_delete_help = "delete aliases"
2778
2782
alias_delete_description = "Delete specified aliases or all aliases if --all is used"
2779
2783
2780
2784
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" )
2781
2786
alias_delete_parser .add_argument ('names' , nargs = argparse .ZERO_OR_MORE , help = 'alias(es) to delete' ,
2782
2787
choices_method = _get_alias_completion_items , descriptive_header = 'Value' )
2783
- alias_delete_parser .add_argument ('-a' , '--all' , action = 'store_true' , help = "delete all aliases" )
2784
2788
2785
2789
@as_subcommand_to ('alias' , 'delete' , alias_delete_parser , help = alias_delete_help )
2786
2790
def _alias_delete (self , args : argparse .Namespace ) -> None :
@@ -2806,21 +2810,29 @@ def _alias_delete(self, args: argparse.Namespace) -> None:
2806
2810
"Without arguments, all aliases will be listed." )
2807
2811
2808
2812
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." )
2809
2817
alias_list_parser .add_argument ('names' , nargs = argparse .ZERO_OR_MORE , help = 'alias(es) to list' ,
2810
2818
choices_method = _get_alias_completion_items , descriptive_header = 'Value' )
2811
2819
2812
2820
@as_subcommand_to ('alias' , 'list' , alias_list_parser , help = alias_delete_help )
2813
2821
def _alias_list (self , args : argparse .Namespace ) -> None :
2814
2822
"""List some or all aliases"""
2823
+ create_cmd = "alias create"
2824
+ if args .with_silent :
2825
+ create_cmd += " --silent"
2826
+
2815
2827
if args .names :
2816
2828
for cur_name in utils .remove_duplicates (args .names ):
2817
2829
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 ]))
2819
2831
else :
2820
2832
self .perror ("Alias '{}' not found" .format (cur_name ))
2821
2833
else :
2822
2834
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 ]))
2824
2836
2825
2837
#############################################################
2826
2838
# Parsers and functions for macro command and subcommands
@@ -2884,6 +2896,9 @@ def do_macro(self, args: argparse.Namespace) -> None:
2884
2896
" will only complete paths while typing a macro." )
2885
2897
2886
2898
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' )
2887
2902
macro_create_parser .add_argument ('name' , help = 'name of this macro' )
2888
2903
macro_create_parser .add_argument ('command' , help = 'what the macro resolves to' ,
2889
2904
choices_method = _get_commands_aliases_and_macros_for_completion )
@@ -2893,7 +2908,6 @@ def do_macro(self, args: argparse.Namespace) -> None:
2893
2908
@as_subcommand_to ('macro' , 'create' , macro_create_parser , help = macro_create_help )
2894
2909
def _macro_create (self , args : argparse .Namespace ) -> None :
2895
2910
"""Create or overwrite a macro"""
2896
-
2897
2911
# Validate the macro name
2898
2912
valid , errmsg = self .statement_parser .is_valid_command (args .name )
2899
2913
if not valid :
@@ -2966,17 +2980,19 @@ def _macro_create(self, args: argparse.Namespace) -> None:
2966
2980
break
2967
2981
2968
2982
# 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
+
2970
2987
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 ))
2972
2988
2973
2989
# macro -> delete
2974
2990
macro_delete_help = "delete macros"
2975
2991
macro_delete_description = "Delete specified macros or all macros if --all is used"
2976
2992
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" )
2977
2994
macro_delete_parser .add_argument ('names' , nargs = argparse .ZERO_OR_MORE , help = 'macro(s) to delete' ,
2978
2995
choices_method = _get_macro_completion_items , descriptive_header = 'Value' )
2979
- macro_delete_parser .add_argument ('-a' , '--all' , action = 'store_true' , help = "delete all macros" )
2980
2996
2981
2997
@as_subcommand_to ('macro' , 'delete' , macro_delete_parser , help = macro_delete_help )
2982
2998
def _macro_delete (self , args : argparse .Namespace ) -> None :
@@ -3002,21 +3018,29 @@ def _macro_delete(self, args: argparse.Namespace) -> None:
3002
3018
"Without arguments, all macros will be listed." )
3003
3019
3004
3020
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." )
3005
3025
macro_list_parser .add_argument ('names' , nargs = argparse .ZERO_OR_MORE , help = 'macro(s) to list' ,
3006
3026
choices_method = _get_macro_completion_items , descriptive_header = 'Value' )
3007
3027
3008
3028
@as_subcommand_to ('macro' , 'list' , macro_list_parser , help = macro_list_help )
3009
3029
def _macro_list (self , args : argparse .Namespace ) -> None :
3010
3030
"""List some or all macros"""
3031
+ create_cmd = "macro create"
3032
+ if args .with_silent :
3033
+ create_cmd += " --silent"
3034
+
3011
3035
if args .names :
3012
3036
for cur_name in utils .remove_duplicates (args .names ):
3013
3037
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 ))
3015
3039
else :
3016
3040
self .perror ("Macro '{}' not found" .format (cur_name ))
3017
3041
else :
3018
3042
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 ))
3020
3044
3021
3045
def complete_help_command (self , text : str , line : str , begidx : int , endidx : int ) -> List [str ]:
3022
3046
"""Completes the command argument of help"""
@@ -3051,12 +3075,12 @@ def complete_help_subcommands(self, text: str, line: str, begidx: int, endidx: i
3051
3075
3052
3076
help_parser = DEFAULT_ARGUMENT_PARSER (description = "List available commands or provide "
3053
3077
"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" )
3054
3080
help_parser .add_argument ('command' , nargs = argparse .OPTIONAL , help = "command to retrieve help for" ,
3055
3081
completer_method = complete_help_command )
3056
3082
help_parser .add_argument ('subcommands' , nargs = argparse .REMAINDER , help = "subcommand(s) to retrieve help for" ,
3057
3083
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" )
3060
3084
3061
3085
# Get rid of cmd's complete_help() functions so ArgparseCompleter will complete the help command
3062
3086
if getattr (cmd .Cmd , 'complete_help' , None ) is not None :
0 commit comments