22Shared formatter for all SAM CLI commands.
33"""
44
5- from samcli .cli .formatters import RootCommandHelpTextFormatter
5+ from samcli .cli .formatters import RootCommandHelpTextFormatter , get_terminal_width
66from samcli .cli .row_modifiers import BaseLineRowModifier
77
88
@@ -13,7 +13,7 @@ class CommandHelpTextFormatter(RootCommandHelpTextFormatter):
1313
1414 DEFAULT_ADDITIVE_JUSTIFICATION = 6
1515
16- def __init__ (self , options , additive_justification = None , * args , ** kwargs ):
16+ def __init__ (self , options , additive_justification = None , width = None , * args , ** kwargs ):
1717 """
1818 Initialize the formatter.
1919
@@ -24,8 +24,17 @@ def __init__(self, options, additive_justification=None, *args, **kwargs):
2424 additive_justification : int, optional
2525 Override the default additive justification value.
2626 If not provided, uses DEFAULT_ADDITIVE_JUSTIFICATION (6).
27+ width : int, optional
28+ Terminal width. If None, will attempt to detect terminal width.
2729 """
28- super ().__init__ (* args , ** kwargs )
30+ # If width is None, try to detect terminal width and apply padding
31+ if width is None :
32+ detected_width = get_terminal_width ()
33+ if detected_width is not None :
34+ # Apply padding but ensure minimum width of 60
35+ width = max (detected_width - 5 , 60 )
36+
37+ super ().__init__ (width = width , * args , ** kwargs )
2938 justification = (
3039 additive_justification if additive_justification is not None else self .DEFAULT_ADDITIVE_JUSTIFICATION
3140 )
0 commit comments