-
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.
- Loading branch information
Alex Evanczuk
committed
Oct 9, 2022
1 parent
b299d49
commit 17a72a5
Showing
23 changed files
with
570 additions
and
94 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,3 +116,6 @@ Style/AccessorGrouping: | |
|
||
Style/NumericPredicate: | ||
Enabled: false | ||
|
||
Layout/BlockEndNewline: | ||
Enabled: false |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env ruby | ||
# typed: strict | ||
|
||
require_relative '../lib/use_packwerk' | ||
UsePackwerk.start_interactive_mode! |
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 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
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,48 @@ | ||
# typed: strict | ||
|
||
# https://github.com/piotrmurach/tty-prompt | ||
require 'tty-prompt' | ||
|
||
require 'use_packwerk/private/interactive_cli/team_selector' | ||
require 'use_packwerk/private/interactive_cli/pack_selector' | ||
require 'use_packwerk/private/interactive_cli/use_cases/interface' | ||
require 'use_packwerk/private/interactive_cli/use_cases/create' | ||
require 'use_packwerk/private/interactive_cli/use_cases/move' | ||
require 'use_packwerk/private/interactive_cli/use_cases/add_dependency' | ||
require 'use_packwerk/private/interactive_cli/use_cases/get_info' | ||
require 'use_packwerk/private/interactive_cli/use_cases/query' | ||
require 'use_packwerk/private/interactive_cli/use_cases/make_public' | ||
require 'use_packwerk/private/interactive_cli/use_cases/nest' | ||
require 'use_packwerk/private/interactive_cli/use_cases/rename' | ||
require 'use_packwerk/private/interactive_cli/use_cases/update_deprecations' | ||
require 'use_packwerk/private/interactive_cli/use_cases/validate' | ||
|
||
module UsePackwerk | ||
module Private | ||
module InteractiveCli | ||
extend T::Sig | ||
|
||
sig { void } | ||
def self.start! | ||
prompt = TTY::Prompt.new(interrupt: lambda { | ||
puts "\n\nGoodbye! I hope you have a good day." | ||
exit 1 }) | ||
help_text = '(Press ↑/↓ arrow to move, Enter to select and letters to filter)' | ||
choice = prompt.select('Hello! What would you like to do?', | ||
cycle: true, | ||
filter: true, | ||
help: help_text, | ||
show_help: :always, | ||
per_page: 15) do |menu| | ||
menu.enum '.' | ||
|
||
UseCases::Interface.all.each do |use_case| | ||
menu.choice use_case.user_facing_name, use_case | ||
end | ||
end | ||
|
||
choice.perform!(prompt) | ||
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,34 @@ | ||
# typed: strict | ||
|
||
module UsePackwerk | ||
module Private | ||
module InteractiveCli | ||
class PackSelector | ||
extend T::Sig | ||
|
||
sig { params(prompt: TTY::Prompt, question_text: String).returns(ParsePackwerk::Package) } | ||
def self.single_pack_select(prompt, question_text: 'Please select a pack') | ||
packs = ParsePackwerk.all.to_h { |t| [t.name, t] } | ||
prompt.select( | ||
question_text, | ||
packs, | ||
filter: true, | ||
per_page: 10, | ||
show_help: :always | ||
) | ||
end | ||
|
||
sig { params(prompt: TTY::Prompt, question_text: String).returns(T::Array[ParsePackwerk::Package]) } | ||
def self.single_or_all_pack_multi_select(prompt, question_text: 'Please select one or more packs') | ||
prompt.multi_select( | ||
question_text, | ||
ParsePackwerk.all.to_h { |t| [t.name, t] }, | ||
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,35 @@ | ||
# typed: strict | ||
|
||
module UsePackwerk | ||
module Private | ||
module InteractiveCli | ||
class TeamSelector | ||
extend T::Sig | ||
|
||
sig { params(prompt: TTY::Prompt, question_text: String).returns(CodeTeams::Team) } | ||
def self.single_select(prompt, question_text: 'Please select a team owner') | ||
teams = CodeTeams.all.to_h { |t| [t.name, t] } | ||
prompt.select( | ||
question_text, | ||
teams, | ||
filter: true, | ||
per_page: 10, | ||
show_help: :always | ||
) | ||
end | ||
|
||
sig { params(prompt: TTY::Prompt, question_text: String).returns(T::Array[CodeTeams::Team]) } | ||
def self.multi_select(prompt, question_text: 'Please select team owners') | ||
teams = CodeTeams.all.to_h { |t| [t.name, t] } | ||
prompt.multi_select( | ||
question_text, | ||
teams, | ||
filter: true, | ||
per_page: 10, | ||
show_help: :always | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end |
30 changes: 30 additions & 0 deletions
30
lib/use_packwerk/private/interactive_cli/use_cases/add_dependency.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,30 @@ | ||
# typed: strict | ||
|
||
module UsePackwerk | ||
module Private | ||
module InteractiveCli | ||
module UseCases | ||
class AddDependency | ||
extend T::Sig | ||
extend T::Helpers | ||
include Interface | ||
|
||
sig { override.params(prompt: TTY::Prompt).void } | ||
def perform!(prompt) | ||
dependent_pack = PackSelector.single_pack_select(prompt, question_text: 'Please select the pack you are adding a dependency to.') | ||
dependency_pack = PackSelector.single_pack_select(prompt, question_text: "Please select the pack that #{dependent_pack.name} should depend on.") | ||
UsePackwerk.add_dependency!( | ||
pack_name: dependent_pack.name, | ||
dependency_name: dependency_pack.name | ||
) | ||
end | ||
|
||
sig { override.returns(String) } | ||
def user_facing_name | ||
'Add a dependency' | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.