Skip to content

Commit 584a8c9

Browse files
committed
Cli controller name
1 parent 76d70d2 commit 584a8c9

3 files changed

Lines changed: 45 additions & 5 deletions

File tree

.github/workflows/build.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@ jobs:
117117
118118
- name: Build in debug mode
119119
run: |
120-
git clone https://github.com/ddnet-insta/ddnet-insta
120+
git clone --recursive https://github.com/ddnet-insta/ddnet-insta
121121
cd ddnet-insta
122+
ruby ../bin/cli my_snake_debug_mode
122123
mkdir debug
123124
cd debug
124125
${{ matrix.cmake-path }}cmake --version
@@ -129,6 +130,7 @@ jobs:
129130
- name: Build in release mode
130131
run: |
131132
cd ddnet-insta
133+
ruby ../bin/cli MyCamelReleaseMode
132134
mkdir release
133135
cd release
134136
${{ matrix.cmake-path }}cmake -E env ${{ matrix.cmake-init-env }} ${{ matrix.cmake-path }}cmake ${{ matrix.cmake-args }} -DCMAKE_BUILD_TYPE=Release -Werror=dev -DDOWNLOAD_GTEST=ON -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE=. ..

lib/cli.rb

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,53 @@
33
require_relative 'code_generation'
44

55
class Cli
6-
def initialize
6+
def initialize(args)
7+
parse_args(args)
8+
# helps "gets"
9+
# https://stackoverflow.com/a/2166914
10+
ARGV.clear
11+
712
mode = Gamemode.new(
8-
name: 'placeholder'
13+
name: @args[:name]
914
)
1015
# puts mode.gen_cpp_header
1116

1217
puts mode.write_cpp_header
1318
puts mode.write_cpp_source
1419
end
20+
21+
def show_help
22+
end
23+
24+
## TODO: add unit tests once the args are finalized
25+
def parse_args(args)
26+
@args = {}
27+
28+
until args.empty?
29+
arg = args.shift
30+
31+
case arg
32+
when "h", "-h", "--help", "help", "bruder was", "???", "?"
33+
show_help
34+
exit 0
35+
when /^--/
36+
raise "Unknown option '#{arg}'"
37+
when /^-/
38+
raise "Unknown flag '#{arg}'"
39+
else
40+
raise "Unexpected argument '#{arg}'" unless @args[:name].nil?
41+
42+
puts "set name"
43+
@args[:name] = arg
44+
end
45+
end
46+
47+
validate_args
48+
end
49+
50+
def validate_args
51+
raise "Controller name can not be empty" if @args[:name].nil? || @args[:name].empty?
52+
end
1553
end
1654

17-
cli = Cli.new
55+
cli = Cli.new(ARGV)

lib/code_generation.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def ok_to_overwrite?(path)
100100

101101
puts "[!] the following file already exists #{path}"
102102
puts "[!] do you really want to overwrite it? (y/N)"
103-
return true if gets.chomp.match? /[Yy](es)?/
103+
return true if $stdin.gets.chomp.match? /[Yy](es)?/
104104

105105
puts "[!] skipping file ..."
106106
false

0 commit comments

Comments
 (0)