@@ -60,43 +60,58 @@ def __init__(self, file_ops: FileOperations | None = None):
60
60
61
61
def check_and_prompt_tags (self , data : Dict [str , Any ]) -> Dict [str , Any ]:
62
62
"""Check and prompt for tags if empty."""
63
- if "tags" in data and (not data ["tags" ] or data ["tags" ] == []):
64
- if sys .stdin .isatty (): # Interactive terminal
65
- typer .echo ("\n 📋 No tags specified. Would you like to add any common tags?" )
66
- typer .echo ("Available options:" )
67
- for i , tag in enumerate (self .common_tags , 1 ):
68
- typer .echo (f" { i } . { tag } " )
69
- typer .echo (" 0. Skip (no tags)" )
70
-
71
- choices_input = typer .prompt (
72
- "Select options (comma-separated, e.g. '1,2' or '0' to skip)"
73
- )
74
-
75
- try :
76
- choices = [int (x .strip ()) for x in choices_input .split ("," )]
77
- selected_tags : list [str ] = []
78
-
79
- for choice in choices :
80
- if choice == 0 :
81
- selected_tags = []
82
- break
83
- elif 1 <= choice <= len (self .common_tags ):
84
- tag = self .common_tags [choice - 1 ]
85
- if tag not in selected_tags :
86
- selected_tags .append (tag )
87
-
88
- data ["tags" ] = selected_tags
89
- if selected_tags :
90
- typer .echo (f"✅ Added tags: { ', ' .join (selected_tags )} " )
91
- else :
92
- typer .echo ("✅ No tags added" )
93
-
94
- except ValueError :
95
- typer .echo ("⚠️ Invalid input, skipping tags" )
96
- data ["tags" ] = []
97
-
63
+ if self ._should_prompt_for_tags (data ) and sys .stdin .isatty ():
64
+ selected_tags = self ._prompt_for_tags ()
65
+ data ["tags" ] = selected_tags
66
+ self ._display_tags_result (selected_tags )
98
67
return data
99
68
69
+ def _should_prompt_for_tags (self , data : Dict [str , Any ]) -> bool :
70
+ """Check if we should prompt for tags."""
71
+ return "tags" in data and (not data ["tags" ] or data ["tags" ] == [])
72
+
73
+ def _prompt_for_tags (self ) -> list [str ]:
74
+ """Prompt user for tag selection."""
75
+ self ._display_tag_options ()
76
+ choices_input = typer .prompt ("Select options (comma-separated, e.g. '1,2' or '0' to skip)" )
77
+ return self ._process_tag_choices (choices_input )
78
+
79
+ def _display_tag_options (self ) -> None :
80
+ """Display available tag options."""
81
+ typer .echo ("\n 📋 No tags specified. Would you like to add any common tags?" )
82
+ typer .echo ("Available options:" )
83
+ for i , tag in enumerate (self .common_tags , 1 ):
84
+ typer .echo (f" { i } . { tag } " )
85
+ typer .echo (" 0. Skip (no tags)" )
86
+
87
+ def _process_tag_choices (self , choices_input : str ) -> list [str ]:
88
+ """Process user's tag choices."""
89
+ try :
90
+ choices = [int (x .strip ()) for x in choices_input .split ("," )]
91
+ return self ._build_selected_tags (choices )
92
+ except ValueError :
93
+ typer .echo ("⚠️ Invalid input, skipping tags" )
94
+ return []
95
+
96
+ def _build_selected_tags (self , choices : list [int ]) -> list [str ]:
97
+ """Build list of selected tags from choices."""
98
+ selected_tags : list [str ] = []
99
+ for choice in choices :
100
+ if choice == 0 :
101
+ return []
102
+ if 1 <= choice <= len (self .common_tags ):
103
+ tag = self .common_tags [choice - 1 ]
104
+ if tag not in selected_tags :
105
+ selected_tags .append (tag )
106
+ return selected_tags
107
+
108
+ def _display_tags_result (self , selected_tags : list [str ]) -> None :
109
+ """Display the result of tag selection."""
110
+ if selected_tags :
111
+ typer .echo (f"✅ Added tags: { ', ' .join (selected_tags )} " )
112
+ else :
113
+ typer .echo ("✅ No tags added" )
114
+
100
115
def auto_set_dummy_return (self , data : Dict [str , Any ]) -> Dict [str , Any ]:
101
116
"""Auto-set dummy_return based on return_type."""
102
117
if "dummy_return" not in data and "return_type" in data :
0 commit comments