hadron 0.1.3 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5789e8b8a04dc4e123db597eebdc97e4fa0a97d5e1df1747cd8f6b78bed40ada
4
- data.tar.gz: d27140dbc167d46189d967878db79cc429a47c8c4c36cb5fc83617cc48103d76
3
+ metadata.gz: 8d100356d8e2274c4bf905faf27dfe83fedbd0a4d2d04a2c27d25d6a9448e687
4
+ data.tar.gz: 0502ca57031a8040518e06036759ccd73eff72c2f29a75e532c5de8d37e19c0a
5
5
  SHA512:
6
- metadata.gz: 6d6504fcfee5ebeb1020ad01e55960686fa04399cd39ffb74b5bdb3db3729911257645525a73d7eef68247753c8782739bf838abde8a53c1ff48c03ef38a2092
7
- data.tar.gz: 61edf40b2de032a523f6a61d630cb759ef36f36e1877e27c1ed447a5639f77010d724abf03d6168c505b8deedc2c2221a87bc98968591f60b2e527ab4c2a21f4
6
+ metadata.gz: 3d6190786df02e902da5132e916c9a98079b80cab0062025a5b104597fcc19e030c38a6f685582f69f979faeef46c36f77b2cd14f89abcdfa77f6f4f5b424524
7
+ data.tar.gz: c2b25b3debf03274a7eb30eb888be747a3dccf3762a5a7a7a2af6b41a03b64fb8aef5296992a610b32b93efbcb07059a88294eb9e7081402750d40390ceee98d
data/Gemfile CHANGED
@@ -9,4 +9,3 @@ gem "proto_dsl", "~> 0.1.1"
9
9
  gem "rake", "~> 13.0"
10
10
  gem "rspec", "~> 3.0"
11
11
  gem "rubocop", "~> 1.21"
12
- gem "thor", "~> 1.2"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hadron (0.1.3)
4
+ hadron (0.1.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -43,7 +43,6 @@ GEM
43
43
  rubocop-ast (1.24.0)
44
44
  parser (>= 3.1.1.0)
45
45
  ruby-progressbar (1.11.0)
46
- thor (1.2.1)
47
46
  unicode-display_width (2.3.0)
48
47
 
49
48
  PLATFORMS
@@ -56,7 +55,6 @@ DEPENDENCIES
56
55
  rake (~> 13.0)
57
56
  rspec (~> 3.0)
58
57
  rubocop (~> 1.21)
59
- thor (~> 1.2)
60
58
 
61
59
  BUNDLED WITH
62
60
  2.3.15
data/bin/hadron CHANGED
@@ -1,10 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'thor'
4
3
  require 'hadron'
5
4
 
5
+ cli = Hadron::CommandLine.new
6
+
6
7
  # Define the `create` subcommand
7
- command :create do |c|
8
+ cli.command :create do |c|
8
9
  c.desc "Create a new project"
9
10
  c.arg_name "project_name"
10
11
 
@@ -15,7 +16,7 @@ command :create do |c|
15
16
  end
16
17
 
17
18
  # Define the `db` subcommand
18
- command :db do |c|
19
+ cli.command :db do |c|
19
20
  # Define the `create` subcommand for `db`
20
21
  c.command :create do |create|
21
22
  create.desc "Create a database"
@@ -34,7 +35,7 @@ command :db do |c|
34
35
  end
35
36
 
36
37
  # Define the `generate` subcommand
37
- command :generate do |c|
38
+ cli.command :generate do |c|
38
39
  c.desc "Generate boilerplate code"
39
40
 
40
41
  # Define the `scaffold` subcommand for `generate`
@@ -48,3 +49,5 @@ command :generate do |c|
48
49
  end
49
50
  end
50
51
  end
52
+
53
+ cli.run(ARGV)
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hadron
4
+ class Command
5
+ def initialize(name)
6
+ @name = name
7
+ @subcommands = {}
8
+ end
9
+
10
+ def desc(description)
11
+ @description = description
12
+ end
13
+
14
+ def arg_name(name)
15
+ @arg_name = name
16
+ end
17
+
18
+ def action(&block)
19
+ @action = block
20
+ end
21
+
22
+ def command(name, &block)
23
+ cmd = Command.new(name)
24
+ cmd.instance_eval(&block)
25
+ @subcommands[name] = cmd
26
+ end
27
+
28
+ def run(args)
29
+ if @subcommands.empty?
30
+ # This command has no subcommands, so it must have an action
31
+ @action.call(args)
32
+ else
33
+ # This command has subcommands, so the next argument should be a subcommand name
34
+ subcmd_name = args.shift
35
+ subcmd = @subcommands[subcmd_name]
36
+
37
+ if subcmd
38
+ subcmd.run(args)
39
+ else
40
+ puts "Unknown subcommand for '#{@name}': #{subcmd_name}"
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./command"
4
+
5
+ module Hadron
6
+ class CommandLine
7
+ def initialize
8
+ @commands = {}
9
+ end
10
+
11
+ def command(name, &block)
12
+ cmd = Command.new(name)
13
+ cmd.instance_eval(&block)
14
+ @commands[name] = cmd
15
+ end
16
+
17
+ def run(args)
18
+ cmd_name = args.shift
19
+ cmd = @commands[cmd_name]
20
+
21
+ if cmd
22
+ cmd.run(args)
23
+ else
24
+ puts "Unknown command: #{cmd_name}"
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hadron
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.5"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hadron
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sylvance
@@ -30,6 +30,8 @@ files:
30
30
  - bin/hadron
31
31
  - hadron.gemspec
32
32
  - lib/hadron.rb
33
+ - lib/hadron/command.rb
34
+ - lib/hadron/command_line.rb
33
35
  - lib/hadron/version.rb
34
36
  homepage: https://github.com/Sylvance/hadron
35
37
  licenses: []