Skip to content
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
1 change: 1 addition & 0 deletions .rubocop.sorbet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Sorbet/EnforceSigilOrder:

Sorbet/EnforceSignatures:
Enabled: true
Style: rbs
Exclude:
- lib/cli/kit/sorbet_runtime_stub.rb
- "test/**/*"
Expand Down
3 changes: 1 addition & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ inherit_gem:
inherit_from:
- .rubocop.sorbet.yml

require:
- rubocop-sorbet
plugins: rubocop-sorbet

AllCops:
Exclude:
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ group :development, :test do
end

group :typecheck do
gem 'sorbet-static-and-runtime'
gem 'sorbet-static'
gem 'tapioca', require: false
end

Expand Down
44 changes: 21 additions & 23 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ GEM
cli-ui (2.4.0)
docile (1.4.1)
erubi (1.13.1)
json (2.13.2)
json (2.15.1)
language_server-protocol (3.17.0.5)
lint_roller (1.1.0)
logger (1.7.0)
Expand All @@ -33,30 +33,29 @@ GEM
parser (3.3.9.0)
ast (~> 2.4.1)
racc
prism (1.4.0)
prism (1.5.1)
racc (1.8.1)
rainbow (3.1.1)
rake (13.3.0)
rbi (0.3.6)
prism (~> 1.0)
rbs (>= 3.4.4)
rbs (3.9.4)
rbs (3.9.5)
logger
regexp_parser (2.10.0)
rexml (3.4.1)
rubocop (1.79.0)
regexp_parser (2.11.3)
rexml (3.4.4)
rubocop (1.81.1)
json (~> 2.3)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.46.0, < 2.0)
rubocop-ast (>= 1.47.1, < 2.0)
ruby-progressbar (~> 1.7)
tsort (>= 0.2.0)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.46.0)
rubocop-ast (1.47.1)
parser (>= 3.3.7.2)
prism (~> 1.4)
rubocop-rake (0.7.1)
Expand All @@ -75,15 +74,15 @@ GEM
simplecov_json_formatter (~> 0.1)
simplecov-html (0.13.2)
simplecov_json_formatter (0.1.4)
sorbet (0.5.12358)
sorbet-static (= 0.5.12358)
sorbet-runtime (0.5.12358)
sorbet-static (0.5.12358-aarch64-linux)
sorbet-static (0.5.12358-universal-darwin)
sorbet-static (0.5.12358-x86_64-linux)
sorbet-static-and-runtime (0.5.12358)
sorbet (= 0.5.12358)
sorbet-runtime (= 0.5.12358)
sorbet (0.6.12627)
sorbet-static (= 0.6.12627)
sorbet-runtime (0.6.12627)
sorbet-static (0.6.12627-aarch64-linux)
sorbet-static (0.6.12627-universal-darwin)
sorbet-static (0.6.12627-x86_64-linux)
sorbet-static-and-runtime (0.6.12627)
sorbet (= 0.6.12627)
sorbet-runtime (= 0.6.12627)
spoom (1.6.3)
erubi (>= 1.10.0)
prism (>= 0.28.0)
Expand All @@ -102,10 +101,9 @@ GEM
thor (>= 1.2.0)
yard-sorbet
thor (1.4.0)
tsort (0.2.0)
unicode-display_width (3.1.4)
unicode-emoji (~> 4.0, >= 4.0.4)
unicode-emoji (4.0.4)
unicode-display_width (3.2.0)
unicode-emoji (~> 4.1)
unicode-emoji (4.1.0)
yard (0.9.37)
yard-sorbet (0.9.0)
sorbet-runtime
Expand All @@ -131,7 +129,7 @@ DEPENDENCIES
rubocop-shopify
rubocop-sorbet
simplecov
sorbet-static-and-runtime
sorbet-static
tapioca

BUNDLED WITH
Expand Down
1 change: 0 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ $LOAD_PATH.unshift(File.expand_path('../lib', __FILE__))
require 'rake/testtask'
require 'rubocop/rake_task'
require 'bundler/gem_tasks'
require 'sorbet-runtime' unless ENV['BUNDLE_WITHOUT'] == 'typecheck'

TEST_ROOT = File.expand_path('../test', __FILE__)

Expand Down
1 change: 0 additions & 1 deletion bin/testunit
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require 'rubygems'
require 'bundler/setup'
require 'sorbet-runtime' unless ENV['BUNDLE_WITHOUT'] == 'typecheck'

root = File.expand_path('../..', __FILE__)
CLI_TEST_ROOT = root + '/test'
Expand Down
2 changes: 1 addition & 1 deletion examples/minimal/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
registry = CommandRegistry.new(default: 'hello')
registry.add(
Class.new(BaseCommand) do
sig { params(_args: T::Array[String], _name: String).void }
#: (Array[String], String) -> void
def call(_args, _name)
puts 'hello, world!'
end
Expand Down
7 changes: 4 additions & 3 deletions examples/single-file/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module Commands
Registry = CLI::Kit::CommandRegistry.new(default: 'hello')

class << self
sig { params(const: Symbol, cmd: String, path: String, lamda_const: T.proc.returns(Example::Command)).void }
#: (Symbol const, String cmd, String path, ^-> Example::Command lamda_const) -> void
def register(const, cmd, path, lamda_const)
autoload(const, path)
Registry.add(lamda_const, cmd)
Expand All @@ -25,7 +25,8 @@ def register(const, cmd, path, lamda_const)
end

class Hello < Example::Command
sig { override.params(_args: T::Array[String], _name: String).void }
# @override
#: (Array[String] _args, String _name) -> void
def call(_args, _name)
puts 'hello, world!'
end
Expand All @@ -34,7 +35,7 @@ def call(_args, _name)

module EntryPoint
class << self
sig { params(args: T::Array[String]).void }
#: (Array[String] args) -> void
def call(args)
cmd, command_name, args = Example::Resolver.call(args)
Example::Executor.call(cmd, command_name, args)
Expand Down
8 changes: 1 addition & 7 deletions gen/lib/gen/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@

module Gen
module Commands
extend T::Sig

Registry = CLI::Kit::CommandRegistry.new(default: 'help')

class << self
extend T::Sig

sig do
params(const: Symbol, cmd: String, path: String, lamda_const: T.proc.returns(T.class_of(Gen::Command))).void
end
#: (Symbol const, String cmd, String path, ^-> singleton(Gen::Command) lamda_const) -> void
def register(const, cmd, path, lamda_const)
autoload(const, path)
Registry.add(lamda_const, cmd)
Expand Down
4 changes: 1 addition & 3 deletions gen/lib/gen/commands/help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
module Gen
module Commands
class Help < Gen::Command
extend T::Sig

desc('Show help for a command, or this page')

sig { params(args: T::Array[String], _name: String).void }
#: (Array[String] args, String _name) -> void
def call(args, _name)
Gen::Help.generate(args)
end
Expand Down
8 changes: 2 additions & 6 deletions gen/lib/gen/commands/new.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
module Gen
module Commands
class New < Gen::Command
extend T::Sig

command_name('new')
desc('Create a new project')
long_desc(<<~LONGDESC)
Expand All @@ -18,15 +16,13 @@ class New < Gen::Command
example('mycliapp', "create a new project called 'mycliapp'")

class Opts < CLI::Kit::Opts
extend(T::Sig)

sig { returns(String) }
#: -> String
def project_name
position!
end
end

sig { params(op: Opts, _name: T.untyped).returns(T.untyped) }
#: (Opts op, untyped _name) -> untyped
def invoke(op, _name)
Gen::Generator.run(op.project_name)
end
Expand Down
6 changes: 1 addition & 5 deletions gen/lib/gen/entry_point.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@

module Gen
module EntryPoint
extend T::Sig

class << self
extend T::Sig

sig { params(args: T::Array[String]).void }
#: (Array[String] args) -> void
def call(args)
cmd, command_name, args = Gen::Resolver.call(args)
Gen::Executor.call(cmd, command_name, args)
Expand Down
34 changes: 15 additions & 19 deletions gen/lib/gen/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@

module Gen
class Generator
extend T::Sig

class << self
extend T::Sig

sig { params(project_name: String).void }
#: (String project_name) -> void
def run(project_name)
new(project_name).run
end
Expand Down Expand Up @@ -44,7 +40,7 @@ def run(project_name)
}.freeze
private_constant :BUNDLER_TRANSLATIONS

sig { params(project_name: String).void }
#: (String project_name) -> void
def initialize(project_name)
raise(
CLI::Kit::Abort,
Expand All @@ -54,7 +50,7 @@ def initialize(project_name)
@title_case_project_name = @project_name.sub(/^./, &:upcase)
end

sig { void }
#: -> void
def run
vendor = ask_vendor?
create_project_dir
Expand All @@ -68,12 +64,12 @@ def run

private

sig { returns(T::Boolean) }
#: -> bool
def ask_vendor?
return true if ENV['DEPS'] == 'vendor'
return false if ENV['DEPS'] == 'bundler'

vendor = T.let(nil, T.nilable(String))
vendor = nil #: String?
CLI::UI::Frame.open('Configuration') do
q = 'How would you like the application to consume {{command:cli-kit}} and {{command:cli-ui}}?'
vendor = CLI::UI::Prompt.ask(q) do |c|
Expand All @@ -84,15 +80,15 @@ def ask_vendor?
vendor == 'vendor'
end

sig { void }
#: -> void
def create_project_dir
info(create: '')
FileUtils.mkdir(@project_name)
rescue Errno::EEXIST
error("directory already exists: #{@project_name}")
end

sig { params(translations: T::Hash[String, T.any(FalseClass, String)]).void }
#: (translations: Hash[String, (FalseClass | String)]) -> void
def copy_files(translations:)
each_template_file do |source_name|
target_name = translations.fetch(source_name, source_name)
Expand All @@ -115,7 +111,7 @@ def copy_files(translations:)
end
end

sig { void }
#: -> void
def update_deps
Dir.mktmpdir do |tmp|
clone(tmp, 'cli-ui')
Expand All @@ -127,7 +123,7 @@ def update_deps
end
end

sig { params(dir: String, repo: String).void }
#: (String dir, String repo) -> void
def clone(dir, repo)
info(clone: repo)
out, stat = Open3.capture2e('git', '-C', dir, 'clone', "https://github.com/shopify/#{repo}")
Expand All @@ -137,7 +133,7 @@ def clone(dir, repo)
end
end

sig { params(block: T.proc.params(rel_path: String).void).void }
#: { (String rel_path) -> void } -> void
def each_template_file(&block)
root = Pathname.new(TEMPLATE_ROOT)
Dir.glob("#{TEMPLATE_ROOT}/**/*").each do |f|
Expand All @@ -146,7 +142,7 @@ def each_template_file(&block)
end
end

sig { params(s: String).returns(String) }
#: (String s) -> String
def apply_template_variables(s)
s
.gsub('__app__', @project_name)
Expand All @@ -155,19 +151,19 @@ def apply_template_variables(s)
.gsub('__cli-ui-version__', cli_ui_version)
end

sig { returns(String) }
#: -> String
def cli_kit_version
require 'cli/kit/version'
CLI::Kit::VERSION.to_s
end

sig { returns(String) }
#: -> String
def cli_ui_version
require 'cli/ui/version'
CLI::UI::VERSION.to_s
end

sig { params(create: T.nilable(String), clone: T.nilable(String), run: T.nilable(String)).void }
#: (?create: String?, ?clone: String?, ?run: String?) -> void
def info(create: nil, clone: nil, run: nil)
if clone
puts(CLI::UI.fmt("\t{{bold:{{yellow:clone}}\t#{clone}}}"))
Expand All @@ -178,7 +174,7 @@ def info(create: nil, clone: nil, run: nil)
end
end

sig { params(msg: String).void }
#: (String msg) -> void
def error(msg)
raise(CLI::Kit::Abort, msg)
end
Expand Down
Loading