Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CLI::UI compatibility #52

Merged
merged 4 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
PATH
remote: .
specs:
demo_mode (2.1.0)
demo_mode (2.1.1)
actionpack (>= 6.1, < 8.1)
activejob (>= 6.1, < 8.1)
activerecord (>= 6.1, < 8.1)
activesupport (>= 6.1, < 8.1)
cli-ui (~> 1.3.0)
cli-ui (~> 2.3)
railties (>= 6.1, < 8.1)

GEM
Expand Down Expand Up @@ -84,7 +84,7 @@ GEM
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
cli-ui (1.3.0)
cli-ui (2.3.0)
concurrent-ruby (1.3.5)
connection_pool (2.5.0)
crass (1.0.6)
Expand Down Expand Up @@ -236,6 +236,7 @@ GEM
rubocop (~> 1.61)
ruby-progressbar (1.13.0)
securerandom (0.3.2)
sorbet-runtime (0.5.11820)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
Expand Down Expand Up @@ -285,6 +286,7 @@ DEPENDENCIES
nokogiri (~> 1.17.2)
rspec-rails
securerandom (~> 0.3.2)
sorbet-runtime
sprockets-rails
sqlite3
webrick
Expand Down
3 changes: 2 additions & 1 deletion demo_mode.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Gem::Specification.new do |s|
s.add_dependency 'activejob', rails_constraints
s.add_dependency 'activerecord', rails_constraints
s.add_dependency 'activesupport', rails_constraints
s.add_dependency 'cli-ui', '~> 1.3.0'
s.add_dependency 'cli-ui', '~> 2.3'
s.add_dependency 'railties', rails_constraints

s.add_development_dependency 'actionmailer', rails_constraints
Expand All @@ -37,6 +37,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'factory_bot'
s.add_development_dependency 'net-smtp'
s.add_development_dependency 'rspec-rails'
s.add_development_dependency 'sorbet-runtime'
s.add_development_dependency 'sprockets-rails'
s.add_development_dependency 'sqlite3'
s.add_development_dependency 'webrick'
Expand Down
8 changes: 5 additions & 3 deletions gemfiles/rails_6_1.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
PATH
remote: ..
specs:
demo_mode (2.1.0)
demo_mode (2.1.1)
actionpack (>= 6.1, < 8.1)
activejob (>= 6.1, < 8.1)
activerecord (>= 6.1, < 8.1)
activesupport (>= 6.1, < 8.1)
cli-ui (~> 1.3.0)
cli-ui (~> 2.3)
railties (>= 6.1, < 8.1)

GEM
Expand Down Expand Up @@ -71,7 +71,7 @@ GEM
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
cli-ui (1.3.0)
cli-ui (2.3.0)
concurrent-ruby (1.3.4)
crass (1.0.6)
cuprite (0.15.1)
Expand Down Expand Up @@ -199,6 +199,7 @@ GEM
rubocop (~> 1.61)
ruby-progressbar (1.13.0)
securerandom (0.3.2)
sorbet-runtime (0.5.11820)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
Expand Down Expand Up @@ -247,6 +248,7 @@ DEPENDENCIES
railties (~> 6.1.0)
rspec-rails
securerandom (~> 0.3.2)
sorbet-runtime
sprockets-rails
sqlite3 (~> 1.4)
webrick
Expand Down
8 changes: 5 additions & 3 deletions gemfiles/rails_7_0.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
PATH
remote: ..
specs:
demo_mode (2.1.0)
demo_mode (2.1.1)
actionpack (>= 6.1, < 8.1)
activejob (>= 6.1, < 8.1)
activerecord (>= 6.1, < 8.1)
activesupport (>= 6.1, < 8.1)
cli-ui (~> 1.3.0)
cli-ui (~> 2.3)
railties (>= 6.1, < 8.1)

GEM
Expand Down Expand Up @@ -73,7 +73,7 @@ GEM
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
cli-ui (1.3.0)
cli-ui (2.3.0)
concurrent-ruby (1.3.4)
crass (1.0.6)
cuprite (0.15.1)
Expand Down Expand Up @@ -202,6 +202,7 @@ GEM
rubocop (~> 1.61)
ruby-progressbar (1.13.0)
securerandom (0.3.2)
sorbet-runtime (0.5.11820)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
Expand Down Expand Up @@ -250,6 +251,7 @@ DEPENDENCIES
railties (~> 7.0.0)
rspec-rails
securerandom (~> 0.3.2)
sorbet-runtime
sprockets-rails
sqlite3 (~> 1.4)
webrick
Expand Down
8 changes: 5 additions & 3 deletions gemfiles/rails_7_1.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
PATH
remote: ..
specs:
demo_mode (2.1.0)
demo_mode (2.1.1)
actionpack (>= 6.1, < 8.1)
activejob (>= 6.1, < 8.1)
activerecord (>= 6.1, < 8.1)
activesupport (>= 6.1, < 8.1)
cli-ui (~> 1.3.0)
cli-ui (~> 2.3)
railties (>= 6.1, < 8.1)

GEM
Expand Down Expand Up @@ -87,7 +87,7 @@ GEM
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
cli-ui (1.3.0)
cli-ui (2.3.0)
concurrent-ruby (1.3.5)
connection_pool (2.5.0)
crass (1.0.6)
Expand Down Expand Up @@ -240,6 +240,7 @@ GEM
rubocop (~> 1.61)
ruby-progressbar (1.13.0)
securerandom (0.3.2)
sorbet-runtime (0.5.11820)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
Expand Down Expand Up @@ -288,6 +289,7 @@ DEPENDENCIES
railties (~> 7.1.0)
rspec-rails
securerandom (~> 0.3.2)
sorbet-runtime
sprockets-rails
sqlite3 (~> 1.7.3)
webrick
Expand Down
8 changes: 5 additions & 3 deletions gemfiles/rails_7_2.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
PATH
remote: ..
specs:
demo_mode (2.1.0)
demo_mode (2.1.1)
actionpack (>= 6.1, < 8.1)
activejob (>= 6.1, < 8.1)
activerecord (>= 6.1, < 8.1)
activesupport (>= 6.1, < 8.1)
cli-ui (~> 1.3.0)
cli-ui (~> 2.3)
railties (>= 6.1, < 8.1)

GEM
Expand Down Expand Up @@ -84,7 +84,7 @@ GEM
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
cli-ui (1.3.0)
cli-ui (2.3.0)
concurrent-ruby (1.3.5)
connection_pool (2.5.0)
crass (1.0.6)
Expand Down Expand Up @@ -236,6 +236,7 @@ GEM
rubocop (~> 1.61)
ruby-progressbar (1.13.0)
securerandom (0.3.2)
sorbet-runtime (0.5.11820)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
Expand Down Expand Up @@ -285,6 +286,7 @@ DEPENDENCIES
railties (~> 7.2.0)
rspec-rails
securerandom (~> 0.3.2)
sorbet-runtime
sprockets-rails
sqlite3 (~> 1.7.3)
webrick
Expand Down
8 changes: 5 additions & 3 deletions gemfiles/rails_8_0.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
PATH
remote: ..
specs:
demo_mode (2.1.0)
demo_mode (2.1.1)
actionpack (>= 6.1, < 8.1)
activejob (>= 6.1, < 8.1)
activerecord (>= 6.1, < 8.1)
activesupport (>= 6.1, < 8.1)
cli-ui (~> 1.3.0)
cli-ui (~> 2.3)
railties (>= 6.1, < 8.1)

GEM
Expand Down Expand Up @@ -84,7 +84,7 @@ GEM
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
cli-ui (1.3.0)
cli-ui (2.3.0)
concurrent-ruby (1.3.5)
connection_pool (2.5.0)
crass (1.0.6)
Expand Down Expand Up @@ -236,6 +236,7 @@ GEM
rubocop (~> 1.61)
ruby-progressbar (1.13.0)
securerandom (0.3.2)
sorbet-runtime (0.5.11820)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
Expand Down Expand Up @@ -286,6 +287,7 @@ DEPENDENCIES
railties (~> 8.0.0)
rspec-rails
securerandom (~> 0.3.2)
sorbet-runtime
sprockets-rails
sqlite3 (>= 2.1)
webrick
Expand Down
71 changes: 39 additions & 32 deletions lib/demo_mode/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,58 +27,65 @@ def created_sessions
private

def ask_next_step
CLI::UI::Prompt.ask('What next?') do |handler|
handler.option("I'm done") do
puts "good bye"
end
handler.option('Keep going') do
prompt_persona
end
case CLI::UI::Prompt.ask("What next?", options: ["I'm done", "Keep going"])
in "I'm done"
puts "good bye"
in "Keep going"
prompt_persona
end
end

def prompt_persona
CLI::UI::Frame.open("{{*}} Generate an Account! {{*}}") do
CLI::UI::Prompt.ask('Which persona should we use?') do |handler|
DemoMode.personas.sort_by { |p| p.name.to_s }.each do |persona|
persona_label = persona.name.to_s.titleize

handler.option(persona_label) do
persona.features.each do |feature|
puts "👉 #{feature}"
end

named_tags = SemanticLogger.named_tags if defined?(SemanticLogger)

variant = variant_for(persona, persona_label)
personas = DemoMode.personas.sort_by { |p| p.name.to_s }

CLI::UI::Spinner.spin("generating account...") do |spinner|
SemanticLogger.push_named_tags(named_tags) if defined?(SemanticLogger)

session = DemoMode::Session.new(persona_name: persona.name, variant: variant)
session.save_and_generate_account!
spinner.update_title('done!')
created_sessions << session
end
end
persona_id = CLI::UI::Prompt.ask('Which persona should we use?') do |handler|
personas.each.with_index do |persona, i|
handler.option(persona_label(persona)) { i.to_s }
end
end

execute_persona(personas[persona_id.to_i])
end

display_personas
ask_next_step
end

def variant_for(persona, persona_label)
def execute_persona(persona)
persona.features.each do |feature|
puts "👉 #{feature}"
end

named_tags = SemanticLogger.named_tags if defined?(SemanticLogger)

variant = variant_for(persona)

CLI::UI::Spinner.spin("generating account...") do |spinner|
SemanticLogger.push_named_tags(named_tags) if defined?(SemanticLogger)

session = DemoMode::Session.new(persona_name: persona.name, variant: variant)
session.save_and_generate_account!
spinner.update_title('done!')
created_sessions << session
end
end

def variant_for(persona)
if persona.variants.keys == ['default']
:default
else
CLI::UI::Prompt.ask(
"Which variant should we use for #{persona_label}?",
options: persona.variants.keys,
)
"Which variant should we use for #{persona_label(persona)}?",
options: persona.variants.keys.map(&:to_s),
).to_sym
end
end

def persona_label(persona)
persona.name.to_s.titleize
end

def display_personas
created_sessions.each do |session|
CLI::UI::Frame.open("{{*}} #{session.persona_name} {{*}}") do
Expand Down
2 changes: 1 addition & 1 deletion lib/demo_mode/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module DemoMode
VERSION = '2.1.0'
VERSION = '2.1.1'
end
1 change: 1 addition & 0 deletions spec/demo_mode/cli_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'spec_helper'
require 'sorbet-runtime'
require 'demo_mode/cli'
Comment on lines 3 to 5
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


RSpec.describe DemoMode::Cli do
Expand Down