From 03b9b95eaf304c765534e818567ff02fa9109ada Mon Sep 17 00:00:00 2001 From: Lily Date: Wed, 2 Feb 2022 20:26:20 +0300 Subject: [PATCH 1/5] Create Goby::read_cli_args --- lib/goby/util.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/goby/util.rb b/lib/goby/util.rb index 0874dd6..e701d95 100644 --- a/lib/goby/util.rb +++ b/lib/goby/util.rb @@ -112,4 +112,8 @@ def load_game(filename) end end + # Reads the ARGV + def read_cli_args(cli_arguments) + end + end From a8c84114cbfba38f513835e596666ba90b9cb8de Mon Sep 17 00:00:00 2001 From: Lily Date: Wed, 2 Feb 2022 21:39:38 +0300 Subject: [PATCH 2/5] Create Goby::GobyCLI and GobyCLI::read_cli_args for console commands --- exe/goby | 3 ++- lib/goby/util.rb | 30 ++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/exe/goby b/exe/goby index 82dbdee..08c0c70 100755 --- a/exe/goby +++ b/exe/goby @@ -1,4 +1,5 @@ #!/usr/bin/env ruby require 'goby' -Goby::Scaffold::simple "goby-project" \ No newline at end of file +# Goby::Scaffold::simple "goby-project" +Goby::GobyCLI::read_cli_args ARGV # ARGV is an array of strings that hold the arguments passed into the CLI \ No newline at end of file diff --git a/lib/goby/util.rb b/lib/goby/util.rb index e701d95..794d335 100644 --- a/lib/goby/util.rb +++ b/lib/goby/util.rb @@ -112,8 +112,34 @@ def load_game(filename) end end - # Reads the ARGV - def read_cli_args(cli_arguments) + # Class for running commands based on CLI input + class GobyCLI + # Default message to be shown if user inputs no arguments in OR user inputs invalid argument + # (I realise the spacing is messed up on the editor but it was the only way i found to make it look good on the console output) + @@DEFAULT_HELP_MESSAGE = + %{Usage: goby +All available goby commands: + init Initialize a new goby project in the current working directory + --version Show the current version of goby + +For more information, visit https://github.com/nskins/goby} + + # Reads the ARGV and runs the given commands + # @param String[] (Array of strings) + def self.read_cli_args(cli_arguments) + user_input = cli_arguments[0] # Gets first arg. Eg: "goby init" would set USER_INPUT to "init" + goby_ver = Gem.loaded_specs["goby"].version + + case user_input + when "init" + puts "Executing init command..." + when "--version", "--ver", "--v" + puts "Using goby v#{goby_ver}" + else + puts @@DEFAULT_HELP_MESSAGE + end + + end end end From db685686b2d18883a17bcf35dc43fc161aa1eb9f Mon Sep 17 00:00:00 2001 From: Lily Date: Wed, 2 Feb 2022 21:42:06 +0300 Subject: [PATCH 3/5] Change goby version message --- lib/goby/util.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/goby/util.rb b/lib/goby/util.rb index 794d335..907f383 100644 --- a/lib/goby/util.rb +++ b/lib/goby/util.rb @@ -134,7 +134,7 @@ def self.read_cli_args(cli_arguments) when "init" puts "Executing init command..." when "--version", "--ver", "--v" - puts "Using goby v#{goby_ver}" + puts "goby v#{goby_ver}" else puts @@DEFAULT_HELP_MESSAGE end From e22b40e3c201b42e2cec79168a32d46b820d3618 Mon Sep 17 00:00:00 2001 From: Lily Date: Wed, 2 Feb 2022 22:22:46 +0300 Subject: [PATCH 4/5] Rewrite Goby::Scaffold::simple and finalise Goby::GobyCLI --- exe/goby | 1 - lib/goby/scaffold.rb | 14 +++++++++----- lib/goby/util.rb | 9 ++++----- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/exe/goby b/exe/goby index 08c0c70..4121776 100755 --- a/exe/goby +++ b/exe/goby @@ -1,5 +1,4 @@ #!/usr/bin/env ruby require 'goby' -# Goby::Scaffold::simple "goby-project" Goby::GobyCLI::read_cli_args ARGV # ARGV is an array of strings that hold the arguments passed into the CLI \ No newline at end of file diff --git a/lib/goby/scaffold.rb b/lib/goby/scaffold.rb index 7de9cc9..f7dc7a6 100644 --- a/lib/goby/scaffold.rb +++ b/lib/goby/scaffold.rb @@ -6,16 +6,20 @@ module Scaffold # Simple starter project w/o testing. # # @param [String] project the project name. - def self.simple(project) + # @param [Boolean] boolean for deciding whether to init project on current or in a new directory + def self.simple # TODO: detect existence of project folder. - + if File.exists? "src" + puts "A src directory already exists, please create a new folder!" + return + end + # Make the directory structure. - Dir.mkdir project dirs = [ '', 'battle', 'entity', 'event', 'item', 'map' ] dirs.each do |dir| - Dir.mkdir "#{project}/src/#{dir}" + Dir.mkdir "src/#{dir}" end # Create the source files. @@ -24,7 +28,7 @@ def self.simple(project) 'src/main.rb': 'main.rb', 'src/map/farm.rb': 'farm.rb' } files.each do |dest, source| - File.open("#{project}/#{dest.to_s}", 'w') do |w| + File.open("#{dest.to_s}", 'w') do |w| w.write(File.read "#{gem_location}/res/scaffold/simple/#{source}") end end diff --git a/lib/goby/util.rb b/lib/goby/util.rb index 907f383..5768815 100644 --- a/lib/goby/util.rb +++ b/lib/goby/util.rb @@ -119,8 +119,8 @@ class GobyCLI @@DEFAULT_HELP_MESSAGE = %{Usage: goby All available goby commands: - init Initialize a new goby project in the current working directory - --version Show the current version of goby + init Initialize a new goby project in the current working directory + --version Show the current version of goby For more information, visit https://github.com/nskins/goby} @@ -128,17 +128,16 @@ class GobyCLI # @param String[] (Array of strings) def self.read_cli_args(cli_arguments) user_input = cli_arguments[0] # Gets first arg. Eg: "goby init" would set USER_INPUT to "init" - goby_ver = Gem.loaded_specs["goby"].version + goby_ver = Gem.loaded_specs["goby"].version # Gets the goby version stated in the gemspec case user_input when "init" - puts "Executing init command..." + Goby::Scaffold::simple when "--version", "--ver", "--v" puts "goby v#{goby_ver}" else puts @@DEFAULT_HELP_MESSAGE end - end end From ed78d254d5ffa6bbcc3fbc53e83b9cb31bc22948 Mon Sep 17 00:00:00 2001 From: Lily Date: Wed, 2 Feb 2022 22:25:40 +0300 Subject: [PATCH 5/5] Rewrite the Scaffold tests to fit the new project creation methods --- .gitignore | 17 ++++-------- Gemfile.lock | 56 ++++++++++++++++++++++++++++++++++++++ spec/goby/scaffold_spec.rb | 13 ++++----- 3 files changed, 66 insertions(+), 20 deletions(-) create mode 100644 Gemfile.lock diff --git a/.gitignore b/.gitignore index 38de12d..e3c6ba8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,3 @@ - -# Created by https://www.gitignore.io/api/ruby - -### Ruby ### *.gem *.rbc /.config @@ -46,15 +42,12 @@ build-iPhoneSimulator/ # for a library or gem, you might want to ignore these files since the code is # intended to run in multiple environments; otherwise, check them in: -Gemfile.lock -.ruby-version -.ruby-gemset +# Gemfile.lock +# .ruby-version +# .ruby-gemset # unless supporting rvm < 1.11.0 or doing something fancy, ignore this: .rvmrc -todo.txt -player.yaml - -#Ignore RubyMine/IntelliJ project files -/.idea/ \ No newline at end of file +# this is the save file +player.yaml \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..6735c93 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,56 @@ +PATH + remote: . + specs: + goby (0.2.0) + +GEM + remote: https://rubygems.org/ + specs: + coveralls (0.8.23) + json (>= 1.8, < 3) + simplecov (~> 0.16.1) + term-ansicolor (~> 1.3) + thor (>= 0.19.4, < 2.0) + tins (~> 1.6) + diff-lcs (1.5.0) + docile (1.4.0) + json (2.6.1) + rake (13.0.6) + rspec (3.10.0) + rspec-core (~> 3.10.0) + rspec-expectations (~> 3.10.0) + rspec-mocks (~> 3.10.0) + rspec-core (3.10.2) + rspec-support (~> 3.10.0) + rspec-expectations (3.10.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.10.0) + rspec-mocks (3.10.3) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.10.0) + rspec-support (3.10.3) + simplecov (0.16.1) + docile (~> 1.1) + json (>= 1.8, < 3) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.2) + sync (0.5.0) + term-ansicolor (1.7.1) + tins (~> 1.0) + thor (1.2.1) + tins (1.31.0) + sync + +PLATFORMS + ruby + +DEPENDENCIES + bundler (~> 1.16) + coveralls + goby! + rake + rspec (~> 3.5) + rspec-mocks + +BUNDLED WITH + 1.17.3 diff --git a/spec/goby/scaffold_spec.rb b/spec/goby/scaffold_spec.rb index 1841c32..7859ad0 100644 --- a/spec/goby/scaffold_spec.rb +++ b/spec/goby/scaffold_spec.rb @@ -4,26 +4,23 @@ RSpec.describe Scaffold do context "simple" do - it "should create the appropriate directories & files" do + it "should create the appropriate directories & files in the current directory" do - project = "goby-project" - Scaffold::simple project + Scaffold::simple # Ensure all of the directories exist. - expect(Dir.exists? "#{project}").to be true [ '', 'battle', 'entity', 'event', 'item', 'map' ].each do |dir| - expect(Dir.exist? "#{project}/src/#{dir}").to be true + expect(Dir.exist? "src/#{dir}").to be true end # Ensure all of the files exist. [ '.gitignore', 'src/main.rb', 'src/map/farm.rb' ].each do |file| - expect(File.exist? "#{project}/#{file}").to be true + expect(File.exist? "#{file}").to be true end # Clean up the scaffolding. - FileUtils.remove_dir project - + FileUtils.remove_dir "src" end end