Class: Sc2::Cli::New

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/sc2ai/cli/new.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



14
15
16
# File 'lib/sc2ai/cli/new.rb', line 14

def self.source_root
  Sc2::Paths.template_root.to_s
end

Instance Method Details

#byeObject



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/sc2ai/cli/new.rb', line 75

def bye
  say ""
  say "Bot generated, next steps:"
  say ""
  say "cd #{@directory} && bundle install", :green
  say ""
  say "Once your project is ready, if you haven't done so, setup SC2 v4.10 with:"
  say ""
  say "bundle exec sc2ai setup410", :green
  say ""
end

#checknameObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/sc2ai/cli/new.rb', line 18

def checkname
  race_arg = Sc2::Cli::New.arguments.find { |a| a.name == "race" }
  unless race_arg.enum.include?(race)
    raise Thor::MalformattedArgumentError, "Invalid race #{race}, must be one of #{race_arg.enum}"
  end

  say "We need to create a filename and classname from botname '#{@botname}'"
  say "You rename classes and organize files in any way, as long as you generate a valid $bot in boot.rb"

  @botname = botname.gsub(/[^0-9a-z]/i, "")
  @directory = @botname.downcase
  @classname = botname.split(/[^0-9a-z]/i).collect { |s| s.sub(/^./, &:upcase) }.join
  @bot_file = @classname.split(/(?=[A-Z])/).join("_").downcase.concat(".rb")
  say "Race: #{race}"
  say "Class name: #{@classname}"
  say "Create directory: ./#{@directory}"
  say "Bot file: ./#{@directory}/#{@bot_file}"

  unless ask("Does this look ok?", limited_to: ["y", "n"], default: "y") == "y"
    raise SystemExit
  end
end

#copy_apiObject



71
72
73
# File 'lib/sc2ai/cli/new.rb', line 71

def copy_api
  directory("new/api", "api")
end

#create_bootObject



51
52
53
# File 'lib/sc2ai/cli/new.rb', line 51

def create_boot
  template("new/boot.rb", "boot.rb")
end

#create_botfileObject



63
64
65
# File 'lib/sc2ai/cli/new.rb', line 63

def create_botfile
  template("new/my_bot.rb", @bot_file)
end

#create_example_matchObject



55
56
57
# File 'lib/sc2ai/cli/new.rb', line 55

def create_example_match
  template("new/run_example_match.rb", "run_example_match.rb")
end

#create_gemfileObject



59
60
61
# File 'lib/sc2ai/cli/new.rb', line 59

def create_gemfile
  template("new/Gemfile", "Gemfile")
end

#create_ignorefileObject



67
68
69
# File 'lib/sc2ai/cli/new.rb', line 67

def create_ignorefile
  template("new/.ladderignore", ".ladderignore")
end

#create_targetObject



41
42
43
44
45
46
47
48
49
# File 'lib/sc2ai/cli/new.rb', line 41

def create_target
  if Pathname("./#{@directory}").exist?
    say "Folder already exists. Refusing to overwrite.", :red
    raise SystemExit
  end

  empty_directory "./#{@directory}"
  self.destination_root = Pathname("./#{@directory}").to_s
end