Class: Rwm::Commands::New

Inherits:
Object
  • Object
show all
Defined in:
lib/rwm/commands/new.rb

Constant Summary collapse

VALID_TEST_FRAMEWORKS =
%w[rspec minitest none].freeze

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ New

Returns a new instance of New.



11
12
13
14
15
# File 'lib/rwm/commands/new.rb', line 11

def initialize(argv)
  @argv = argv
  @test_framework = "rspec"
  parse_options
end

Instance Method Details

#runObject

Raises:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rwm/commands/new.rb', line 17

def run
  type = @argv.shift
  name = @argv.shift

  unless %w[app lib].include?(type)
    $stderr.puts "Usage: rwm new <app|lib> <name>"
    return 1
  end

  unless name && name.match?(/\A[a-z][a-z0-9_]*\z/)
    $stderr.puts "Package name must start with a lowercase letter and contain only lowercase letters, digits, and underscores."
    return 1
  end

  workspace = Workspace.find
  dir = type == "lib" ? "libs" : "apps"
  pkg_path = File.join(workspace.root, dir, name)

  raise PackageExistsError, name if File.directory?(pkg_path)

  scaffold(pkg_path, name, type)
  update_vscode_workspace(workspace)

  puts "Created #{type} '#{name}' at #{dir}/#{name}/"
  puts
  puts "Next steps:"
  puts "  cd #{dir}/#{name}"
  puts "  bundle install"
  puts "  rwm graph    # rebuild the dependency graph"
  0
end