@@ -52,26 +52,47 @@ defmodule LinearCli.CLI.Commands.Issues.Move do
5252 defp resolve_move_project ( issues , options ) do
5353 with { :ok , tid } <- resolve_move_team_id ( options . team || Profiles . default_team ( ) , issues ) ,
5454 { :ok , projects } <- Linear . projects_by_team ( tid , % { search: options . project } ) do
55- project_result ( Projects . project_for ( projects , options . project ) , options . project )
55+ project =
56+ if options . output == "json" do
57+ Projects . project_for_strict ( projects , options . project )
58+ else
59+ Projects . project_for ( projects , options . project )
60+ end
61+
62+ project_result ( project , options . project , options . output )
5663 end
5764 end
5865
59- defp project_result ( nil , search ) ,
66+ defp project_result ( nil , search , "json" ) ,
67+ do:
68+ { :error ,
69+ { :smells_bad , "JSON output requires an exact project match for #{ inspect ( search ) } " } }
70+
71+ defp project_result ( nil , search , _output ) ,
6072 do: { :error , { :smells_bad , "No project found matching #{ inspect ( search ) } " } }
6173
62- defp project_result ( project , _search ) , do: { :ok , project }
74+ defp project_result ( project , _search , _output ) , do: { :ok , project }
6375
6476 defp resolve_move_team_id ( nil , issues ) , do: { :ok , hd ( issues ) . team . id }
6577
6678 defp resolve_move_team_id ( key , _issues ) do
6779 with { :ok , team } <- Linear . find_team ( key ) , do: { :ok , team . id }
6880 end
6981
82+ defp execute_moves_if_confirmed ( issues , _project , % { dry_run: true } , "json" ) do
83+ Display . show ( one_or_many ( issues ) , % { output: "json" } )
84+ :ok
85+ end
86+
7087 defp execute_moves_if_confirmed ( _issues , _project , % { dry_run: true } , _output ) , do: :ok
7188
7289 defp execute_moves_if_confirmed ( issues , project , % { yes: true } , output ) ,
7390 do: apply_moves ( issues , project , output )
7491
92+ defp execute_moves_if_confirmed ( _issues , _project , _flags , "json" ) do
93+ { :error , { :smells_bad , "JSON output requires --yes or --dry-run for issue move" } }
94+ end
95+
7596 defp execute_moves_if_confirmed ( issues , project , _flags , output ) do
7697 if Prompt . confirm_destructive? ( "Proceed with move?" ) ,
7798 do: apply_moves ( issues , project , output ) ,
@@ -127,58 +148,114 @@ defmodule LinearCli.CLI.Commands.Issues.Move do
127148 defp validate_issue_ids ( _issue_ids ) , do: :ok
128149
129150 defp move_issues_by_project ( options , flags ) do
130- team_fn = fn -> WhatFor . team_for ( options . team || Profiles . default_team ( ) ) end
151+ team_key = options . team || Profiles . default_team ( )
152+ team_fn = fn -> WhatFor . team_for ( team_key ) end
131153
132- with { :ok , source } <- resolve_bulk_project ( options . from , team_fn ) ,
133- { :ok , target } <- resolve_bulk_project ( options . to , team_fn ) ,
154+ with :ok <- validate_bulk_team ( team_key , options ) ,
155+ { :ok , source } <- resolve_bulk_project ( options . from , team_fn , options . output ) ,
156+ { :ok , target } <- resolve_bulk_project ( options . to , team_fn , options . output ) ,
134157 :ok <- guard_different_projects ( source , target ) ,
135158 { :ok , issues } <- Linear . issues ( % { project_id: source . id , mine: false , all: flags . all } ) do
136- cond do
137- issues == [ ] ->
138- label = if flags . all , do: "issues" , else: "open issues"
139- Prompt . ok ( "No #{ label } in #{ source . name } to move" )
140- :ok
141-
142- flags . dry_run ->
143- Display . show ( one_or_many ( issues ) , % { output: options . output } )
144- Prompt . ok ( "Would move #{ length ( issues ) } issue(s) from #{ source . name } to #{ target . name } " )
145- :ok
146-
147- not flags . yes and
148- not Prompt . confirm_destructive? (
149- "Move #{ length ( issues ) } issue(s) from #{ source . name } to #{ target . name } ?"
150- ) ->
151- Prompt . warn ( "Move cancelled" )
152-
153- true ->
154- with { :ok , pairs } <- apply_project_moves ( issues , target ) do
155- show_move_results ( pairs , source , target , options . output )
156- end
157- end
159+ handle_bulk_move ( issues , source , target , flags , options )
160+ end
161+ end
162+
163+ defp handle_bulk_move ( [ ] , _source , _target , _flags , % { output: "json" } ) do
164+ Display . show ( [ ] , % { output: "json" } )
165+ :ok
166+ end
167+
168+ defp handle_bulk_move ( [ ] , source , _target , flags , % { output: _output } ) do
169+ label = if flags . all , do: "issues" , else: "open issues"
170+ Prompt . ok ( "No #{ label } in #{ source . name } to move" )
171+ :ok
172+ end
173+
174+ defp handle_bulk_move ( issues , source , target , % { dry_run: true } , options ) do
175+ Display . show ( one_or_many ( issues ) , % { output: options . output } )
176+ print_bulk_dry_run ( issues , source , target , options )
177+ :ok
178+ end
179+
180+ defp handle_bulk_move ( _issues , _source , _target , % { yes: false } , % { output: "json" } ) do
181+ { :error , { :smells_bad , "JSON output requires --yes or --dry-run for issue move" } }
182+ end
183+
184+ defp handle_bulk_move ( issues , source , target , % { yes: false } , options ) do
185+ if Prompt . confirm_destructive? (
186+ "Move #{ length ( issues ) } issue(s) from #{ source . name } to #{ target . name } ?"
187+ ) ,
188+ do: apply_project_moves_and_show ( issues , source , target , options . output ) ,
189+ else: Prompt . warn ( "Move cancelled" )
190+ end
191+
192+ defp handle_bulk_move ( issues , source , target , % { yes: true } , options ) ,
193+ do: apply_project_moves_and_show ( issues , source , target , options . output )
194+
195+ defp print_bulk_dry_run ( _issues , _source , _target , % { output: "json" } ) , do: :ok
196+
197+ defp print_bulk_dry_run ( issues , source , target , % { output: output } ) when output != "json" do
198+ Prompt . ok ( "Would move #{ length ( issues ) } issue(s) from #{ source . name } to #{ target . name } " )
199+ end
200+
201+ defp apply_project_moves_and_show ( issues , source , target , output ) do
202+ with { :ok , pairs } <- apply_project_moves ( issues , target ) do
203+ show_move_results ( pairs , source , target , output )
158204 end
159205 end
160206
161207 # UUID by structure: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx (8-4-4-4-12, dashes at fixed positions)
162208 defp resolve_bulk_project (
163209 << _ :: 8 * 8 , ?- , _ :: 4 * 8 , ?- , _ :: 4 * 8 , ?- , _ :: 4 * 8 , ?- , _ :: 12 * 8 >> = uuid ,
164- _team_fn
210+ _team_fn ,
211+ _output
165212 ) do
166213 short_name = String . slice ( uuid , 0 , 8 ) <> "…"
167214 { :ok , struct ( LinearCli.Linear.Project , % { id: uuid , name: short_name } ) }
168215 end
169216
170- defp resolve_bulk_project ( value , team_fn ) do
217+ defp resolve_bulk_project ( value , team_fn , output ) do
171218 team = team_fn . ( )
172219
173220 with { :ok , projects } <- Linear . projects_by_team ( team . id , % { search: value } ) ,
174- project when not is_nil ( project ) <- Projects . project_for ( projects , value ) do
221+ project when not is_nil ( project ) <- project_for_bulk ( projects , value , output ) do
175222 { :ok , project }
176223 else
177- nil -> { :error , { :smells_bad , "No project found matching #{ value } " } }
178- { :error , reason } -> { :error , reason }
224+ nil ->
225+ if output == "json" do
226+ { :error ,
227+ { :smells_bad , "JSON output requires an exact project match for #{ inspect ( value ) } " } }
228+ else
229+ { :error , { :smells_bad , "No project found matching #{ value } " } }
230+ end
231+
232+ { :error , reason } ->
233+ { :error , reason }
179234 end
180235 end
181236
237+ defp project_for_bulk ( projects , value , "json" ) ,
238+ do: Projects . project_for_strict ( projects , value )
239+
240+ defp project_for_bulk ( projects , value , _output ) ,
241+ do: Projects . project_for ( projects , value )
242+
243+ defp validate_bulk_team ( nil , % { output: "json" , from: from , to: to } ) do
244+ if uuid? ( from ) and uuid? ( to ) do
245+ :ok
246+ else
247+ { :error ,
248+ { :smells_bad , "JSON output requires --team or an active profile for bulk issue move" } }
249+ end
250+ end
251+
252+ defp validate_bulk_team ( _team_key , _options ) , do: :ok
253+
254+ defp uuid? ( << _ :: 8 * 8 , ?- , _ :: 4 * 8 , ?- , _ :: 4 * 8 , ?- , _ :: 4 * 8 , ?- , _ :: 12 * 8 >> ) ,
255+ do: true
256+
257+ defp uuid? ( _value ) , do: false
258+
182259 defp guard_different_projects ( % { id: id } , % { id: id } ) ,
183260 do: { :error , { :smells_bad , "source and target are the same project" } }
184261
0 commit comments