-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Interactive CLI option for move_to_folder (#140)
* first pass at creating a "move pack" interactive cli item Co-authored-by: Perry Hertler <[email protected]> Co-authored-by: Ashley Willard <[email protected]> Co-authored-by: Teal Stannard <[email protected]> * specs for interactive cli changes * bump gem version * formatting * rubocop fix * flatten dirs and add spec for pack dir selector * use += instead of << * use match_array to ignore ordering --------- Co-authored-by: Perry Hertler <[email protected]> Co-authored-by: Ashley Willard <[email protected]> Co-authored-by: Teal Stannard <[email protected]>
- Loading branch information
1 parent
19b4919
commit b48cfc4
Showing
12 changed files
with
215 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
lib/packs/private/interactive_cli/pack_directory_selector.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# typed: strict | ||
|
||
module Packs | ||
module Private | ||
module InteractiveCli | ||
class PackDirectorySelector | ||
extend T::Sig | ||
|
||
sig { params(prompt: TTY::Prompt, question_text: String).returns(String) } | ||
def self.select(prompt, question_text: 'Select a directory') | ||
directories = T.let([], T::Array[String]) | ||
|
||
Packs::Specification.config.pack_paths.each do |path| | ||
directories += Dir.glob(path).select { |f| File.directory? f } | ||
end | ||
|
||
prompt.select( | ||
question_text, | ||
directories, | ||
filter: true, | ||
per_page: 10, | ||
show_help: :always | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# typed: strict | ||
|
||
module Packs | ||
module Private | ||
module InteractiveCli | ||
module UseCases | ||
class MovePack | ||
extend T::Sig | ||
extend T::Helpers | ||
include Interface | ||
|
||
sig { override.params(prompt: TTY::Prompt).void } | ||
def perform!(prompt) | ||
move_type = prompt.select( | ||
'What do you want to do?', | ||
{ | ||
'Move a child pack to be nested under a parent pack' => :move_to_parent, | ||
'Move a pack to a folder that is not a pack' => | ||
:move_to_folder | ||
} | ||
) | ||
|
||
case move_type | ||
when :move_to_parent | ||
child_pack = PackSelector.single_pack_select(prompt, question_text: 'Please select the child pack that will be nested') | ||
parent_pack = PackSelector.single_pack_select(prompt, question_text: 'Please select the pack that will be the parent') | ||
|
||
Packs.move_to_parent!( | ||
parent_name: parent_pack.name, | ||
pack_name: child_pack.name, | ||
per_file_processors: [Packs::RubocopPostProcessor.new, Packs::CodeOwnershipPostProcessor.new] | ||
) | ||
when :move_to_folder | ||
pack = PackSelector.single_pack_select(prompt, question_text: 'Please select the pack that you want to move') | ||
destination = PackDirectorySelector.select(prompt, question_text: "What directory do you want to move #{pack.name} to?") | ||
|
||
if Packs.find(destination) | ||
use_move_to_parent = prompt.select( | ||
"The directory #{destination} contains a pack. Add #{pack.last_name} as a dependency?", | ||
{ 'Yes' => true, 'No' => false } | ||
) | ||
|
||
if use_move_to_parent | ||
Packs.move_to_parent!( | ||
parent_name: destination, | ||
pack_name: pack.name, | ||
per_file_processors: [Packs::RubocopPostProcessor.new, Packs::CodeOwnershipPostProcessor.new] | ||
) | ||
|
||
return | ||
end | ||
end | ||
|
||
Packs.move_to_folder!( | ||
pack_name: pack.name, | ||
destination: destination, | ||
per_file_processors: [Packs::RubocopPostProcessor.new, Packs::CodeOwnershipPostProcessor.new] | ||
) | ||
end | ||
end | ||
|
||
sig { override.returns(String) } | ||
def user_facing_name | ||
'Move a pack' | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
31 changes: 0 additions & 31 deletions
31
lib/packs/private/interactive_cli/use_cases/move_to_parent.rb
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Gem::Specification.new do |spec| | ||
spec.name = 'packs' | ||
spec.version = '0.0.38' | ||
spec.version = '0.0.39' | ||
spec.authors = ['Gusto Engineers'] | ||
spec.email = ['[email protected]'] | ||
|
||
|
27 changes: 27 additions & 0 deletions
27
spec/packs/private/interactive_cli/pack_directory_selector_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'tty/prompt/test' | ||
|
||
module Packs | ||
RSpec.describe Private::InteractiveCli::PackDirectorySelector do | ||
let(:prompt) { TTY::Prompt::Test.new } | ||
|
||
it 'passes pack subdirectories to the prompt' do | ||
write_file 'packs/admin/.keep' | ||
write_file 'packs/utilities/subdir/.keep' | ||
write_file 'not_packs/some_other_dir/.keep' | ||
|
||
expected = [ | ||
'packs/admin', | ||
'packs/utilities', | ||
'packs/utilities/subdir' | ||
] | ||
|
||
expect(prompt).to receive(:select) do |_, directories, _, _, _| | ||
expect(directories).to match_array(expected) | ||
end.and_return(expected.first) | ||
|
||
described_class.select(prompt) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters