Class: Sc2::Cli::New
- Inherits:
-
Thor::Group
- Object
- Thor::Group
- Sc2::Cli::New
- Includes:
- Thor::Actions
- Defined in:
- lib/sc2ai/cli/new.rb
Class Method Summary collapse
Instance Method Summary collapse
- #bye ⇒ Object
- #checkname ⇒ Object
- #copy_api ⇒ Object
- #create_boot ⇒ Object
- #create_botfile ⇒ Object
- #create_example_match ⇒ Object
- #create_gemfile ⇒ Object
- #create_ignorefile ⇒ Object
- #create_target ⇒ Object
Class Method Details
.source_root ⇒ Object
15 16 17 |
# File 'lib/sc2ai/cli/new.rb', line 15 def self.source_root Sc2::Paths.template_root.to_s end |
Instance Method Details
#bye ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/sc2ai/cli/new.rb', line 76 def bye say "" say "Bot generated, next steps:" say "" say "cd #{@directory} && bundle install", :cyan say "" say "Afterwards, it is recommended to setup SC2 to match the ladder version with:" say "" say "bundle exec sc2ai download_ladder_version", :cyan say "" say "Refer to the docs to get the 'AI Edition' maps or further help: https://sc2ai.pages.dev/" say "" end |
#checkname ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/sc2ai/cli/new.rb', line 19 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_api ⇒ Object
72 73 74 |
# File 'lib/sc2ai/cli/new.rb', line 72 def copy_api directory("new/api", "api") end |
#create_boot ⇒ Object
52 53 54 |
# File 'lib/sc2ai/cli/new.rb', line 52 def create_boot template("new/boot.rb", "boot.rb") end |
#create_botfile ⇒ Object
64 65 66 |
# File 'lib/sc2ai/cli/new.rb', line 64 def create_botfile template("new/my_bot.rb", @bot_file) end |
#create_example_match ⇒ Object
56 57 58 |
# File 'lib/sc2ai/cli/new.rb', line 56 def create_example_match template("new/run_example_match.rb", "run_example_match.rb") end |
#create_gemfile ⇒ Object
60 61 62 |
# File 'lib/sc2ai/cli/new.rb', line 60 def create_gemfile template("new/Gemfile", "Gemfile") end |
#create_ignorefile ⇒ Object
68 69 70 |
# File 'lib/sc2ai/cli/new.rb', line 68 def create_ignorefile template("new/.ladderignore", ".ladderignore") end |
#create_target ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/sc2ai/cli/new.rb', line 42 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 |