@@ -2729,6 +2729,9 @@ def do_alias(self, args: argparse.Namespace) -> None:
2729
2729
" alias create save_results print_results \" >\" out.txt\n " )
2730
2730
2731
2731
alias_create_parser = DEFAULT_ARGUMENT_PARSER (description = alias_create_description , epilog = alias_create_epilog )
2732
+ alias_create_parser .add_argument ('-s' , '--silent' , action = 'store_true' ,
2733
+ help = 'do not print message confirming alias was created or\n '
2734
+ 'overwritten' )
2732
2735
alias_create_parser .add_argument ('name' , help = 'name of this alias' )
2733
2736
alias_create_parser .add_argument ('command' , help = 'what the alias resolves to' ,
2734
2737
choices_method = _get_commands_aliases_and_macros_for_completion )
@@ -2738,7 +2741,6 @@ def do_alias(self, args: argparse.Namespace) -> None:
2738
2741
@as_subcommand_to ('alias' , 'create' , alias_create_parser , help = alias_create_description .lower ())
2739
2742
def _alias_create (self , args : argparse .Namespace ) -> None :
2740
2743
"""Create or overwrite an alias"""
2741
-
2742
2744
# Validate the alias name
2743
2745
valid , errmsg = self .statement_parser .is_valid_command (args .name )
2744
2746
if not valid :
@@ -2766,16 +2768,18 @@ def _alias_create(self, args: argparse.Namespace) -> None:
2766
2768
# Set the alias
2767
2769
result = "overwritten" if args .name in self .aliases else "created"
2768
2770
self .aliases [args .name ] = value
2769
- self .poutput ("Alias '{}' {}" .format (args .name , result ))
2771
+
2772
+ if not args .silent :
2773
+ self .poutput ("Alias '{}' {}" .format (args .name , result ))
2770
2774
2771
2775
# alias -> delete
2772
2776
alias_delete_help = "delete aliases"
2773
2777
alias_delete_description = "Delete specified aliases or all aliases if --all is used"
2774
2778
2775
2779
alias_delete_parser = DEFAULT_ARGUMENT_PARSER (description = alias_delete_description )
2780
+ alias_delete_parser .add_argument ('-a' , '--all' , action = 'store_true' , help = "delete all aliases" )
2776
2781
alias_delete_parser .add_argument ('names' , nargs = argparse .ZERO_OR_MORE , help = 'alias(es) to delete' ,
2777
2782
choices_method = _get_alias_completion_items , descriptive_header = 'Value' )
2778
- alias_delete_parser .add_argument ('-a' , '--all' , action = 'store_true' , help = "delete all aliases" )
2779
2783
2780
2784
@as_subcommand_to ('alias' , 'delete' , alias_delete_parser , help = alias_delete_help )
2781
2785
def _alias_delete (self , args : argparse .Namespace ) -> None :
@@ -2801,21 +2805,29 @@ def _alias_delete(self, args: argparse.Namespace) -> None:
2801
2805
"Without arguments, all aliases will be listed." )
2802
2806
2803
2807
alias_list_parser = DEFAULT_ARGUMENT_PARSER (description = alias_list_description )
2808
+ alias_list_parser .add_argument ('-w' , '--with_silent' , action = 'store_true' ,
2809
+ help = "include --silent flag with listed aliases\n "
2810
+ "Use this option when saving to a startup script that\n "
2811
+ "should silently create aliases." )
2804
2812
alias_list_parser .add_argument ('names' , nargs = argparse .ZERO_OR_MORE , help = 'alias(es) to list' ,
2805
2813
choices_method = _get_alias_completion_items , descriptive_header = 'Value' )
2806
2814
2807
2815
@as_subcommand_to ('alias' , 'list' , alias_list_parser , help = alias_delete_help )
2808
2816
def _alias_list (self , args : argparse .Namespace ) -> None :
2809
2817
"""List some or all aliases"""
2818
+ create_cmd = "alias create"
2819
+ if args .with_silent :
2820
+ create_cmd += " --silent"
2821
+
2810
2822
if args .names :
2811
2823
for cur_name in utils .remove_duplicates (args .names ):
2812
2824
if cur_name in self .aliases :
2813
- self .poutput ("alias create {} {}" .format (cur_name , self .aliases [cur_name ]))
2825
+ self .poutput ("{} {} {}" .format (create_cmd , cur_name , self .aliases [cur_name ]))
2814
2826
else :
2815
2827
self .perror ("Alias '{}' not found" .format (cur_name ))
2816
2828
else :
2817
2829
for cur_alias in sorted (self .aliases , key = self .default_sort_key ):
2818
- self .poutput ("alias create {} {}" .format (cur_alias , self .aliases [cur_alias ]))
2830
+ self .poutput ("{} {} {}" .format (create_cmd , cur_alias , self .aliases [cur_alias ]))
2819
2831
2820
2832
#############################################################
2821
2833
# Parsers and functions for macro command and subcommands
@@ -2879,6 +2891,9 @@ def do_macro(self, args: argparse.Namespace) -> None:
2879
2891
" will only complete paths while typing a macro." )
2880
2892
2881
2893
macro_create_parser = DEFAULT_ARGUMENT_PARSER (description = macro_create_description , epilog = macro_create_epilog )
2894
+ macro_create_parser .add_argument ('-s' , '--silent' , action = 'store_true' ,
2895
+ help = 'do not print message confirming macro was created or\n '
2896
+ 'overwritten' )
2882
2897
macro_create_parser .add_argument ('name' , help = 'name of this macro' )
2883
2898
macro_create_parser .add_argument ('command' , help = 'what the macro resolves to' ,
2884
2899
choices_method = _get_commands_aliases_and_macros_for_completion )
@@ -2888,7 +2903,6 @@ def do_macro(self, args: argparse.Namespace) -> None:
2888
2903
@as_subcommand_to ('macro' , 'create' , macro_create_parser , help = macro_create_help )
2889
2904
def _macro_create (self , args : argparse .Namespace ) -> None :
2890
2905
"""Create or overwrite a macro"""
2891
-
2892
2906
# Validate the macro name
2893
2907
valid , errmsg = self .statement_parser .is_valid_command (args .name )
2894
2908
if not valid :
@@ -2963,15 +2977,17 @@ def _macro_create(self, args: argparse.Namespace) -> None:
2963
2977
# Set the macro
2964
2978
result = "overwritten" if args .name in self .macros else "created"
2965
2979
self .macros [args .name ] = Macro (name = args .name , value = value , minimum_arg_count = max_arg_num , arg_list = arg_list )
2966
- self .poutput ("Macro '{}' {}" .format (args .name , result ))
2980
+
2981
+ if not args .silent :
2982
+ self .poutput ("Macro '{}' {}" .format (args .name , result ))
2967
2983
2968
2984
# macro -> delete
2969
2985
macro_delete_help = "delete macros"
2970
2986
macro_delete_description = "Delete specified macros or all macros if --all is used"
2971
2987
macro_delete_parser = DEFAULT_ARGUMENT_PARSER (description = macro_delete_description )
2988
+ macro_delete_parser .add_argument ('-a' , '--all' , action = 'store_true' , help = "delete all macros" )
2972
2989
macro_delete_parser .add_argument ('names' , nargs = argparse .ZERO_OR_MORE , help = 'macro(s) to delete' ,
2973
2990
choices_method = _get_macro_completion_items , descriptive_header = 'Value' )
2974
- macro_delete_parser .add_argument ('-a' , '--all' , action = 'store_true' , help = "delete all macros" )
2975
2991
2976
2992
@as_subcommand_to ('macro' , 'delete' , macro_delete_parser , help = macro_delete_help )
2977
2993
def _macro_delete (self , args : argparse .Namespace ) -> None :
@@ -2997,21 +3013,29 @@ def _macro_delete(self, args: argparse.Namespace) -> None:
2997
3013
"Without arguments, all macros will be listed." )
2998
3014
2999
3015
macro_list_parser = DEFAULT_ARGUMENT_PARSER (description = macro_list_description )
3016
+ macro_list_parser .add_argument ('-w' , '--with_silent' , action = 'store_true' ,
3017
+ help = "include --silent flag with listed macros\n "
3018
+ "Use this option when saving to a startup script that\n "
3019
+ "should silently create macros." )
3000
3020
macro_list_parser .add_argument ('names' , nargs = argparse .ZERO_OR_MORE , help = 'macro(s) to list' ,
3001
3021
choices_method = _get_macro_completion_items , descriptive_header = 'Value' )
3002
3022
3003
3023
@as_subcommand_to ('macro' , 'list' , macro_list_parser , help = macro_list_help )
3004
3024
def _macro_list (self , args : argparse .Namespace ) -> None :
3005
3025
"""List some or all macros"""
3026
+ create_cmd = "macro create"
3027
+ if args .with_silent :
3028
+ create_cmd += " --silent"
3029
+
3006
3030
if args .names :
3007
3031
for cur_name in utils .remove_duplicates (args .names ):
3008
3032
if cur_name in self .macros :
3009
- self .poutput ("macro create {} {}" .format (cur_name , self .macros [cur_name ].value ))
3033
+ self .poutput ("{} {} {}" .format (create_cmd , cur_name , self .macros [cur_name ].value ))
3010
3034
else :
3011
3035
self .perror ("Macro '{}' not found" .format (cur_name ))
3012
3036
else :
3013
3037
for cur_macro in sorted (self .macros , key = self .default_sort_key ):
3014
- self .poutput ("macro create {} {}" .format (cur_macro , self .macros [cur_macro ].value ))
3038
+ self .poutput ("{} {} {}" .format (create_cmd , cur_macro , self .macros [cur_macro ].value ))
3015
3039
3016
3040
def complete_help_command (self , text : str , line : str , begidx : int , endidx : int ) -> List [str ]:
3017
3041
"""Completes the command argument of help"""
@@ -3046,12 +3070,12 @@ def complete_help_subcommands(self, text: str, line: str, begidx: int, endidx: i
3046
3070
3047
3071
help_parser = DEFAULT_ARGUMENT_PARSER (description = "List available commands or provide "
3048
3072
"detailed help for a specific command" )
3073
+ help_parser .add_argument ('-v' , '--verbose' , action = 'store_true' ,
3074
+ help = "print a list of all commands with descriptions of each" )
3049
3075
help_parser .add_argument ('command' , nargs = argparse .OPTIONAL , help = "command to retrieve help for" ,
3050
3076
completer_method = complete_help_command )
3051
3077
help_parser .add_argument ('subcommands' , nargs = argparse .REMAINDER , help = "subcommand(s) to retrieve help for" ,
3052
3078
completer_method = complete_help_subcommands )
3053
- help_parser .add_argument ('-v' , '--verbose' , action = 'store_true' ,
3054
- help = "print a list of all commands with descriptions of each" )
3055
3079
3056
3080
# Get rid of cmd's complete_help() functions so ArgparseCompleter will complete the help command
3057
3081
if getattr (cmd .Cmd , 'complete_help' , None ) is not None :
0 commit comments