belt 0.2.15 → 0.2.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d0a1075ea8085b2214af4991dd2288fec5decd5f0f6d92b6ed12fe135ff152b9
4
- data.tar.gz: bb8db7d0b4a9a39f9cc5e58a77a411f1c78cf885ab5e0ed6353772e386653f95
3
+ metadata.gz: 1dc14fd7c99d9f85c8e3d47cfdec53775ca3b433e1cc25d755793d4ab7ef4a39
4
+ data.tar.gz: '06921a570cc8fc02263861e2be72808ed56af36dda1f1613668bbc186d63712a'
5
5
  SHA512:
6
- metadata.gz: 0f77fe7616521e842fe0836ccb9ab7df6c4306dffc58838c647ce217de2616b967d9b80fccf5ca8708613e112dc771c22eeee091d652a25e0a19290319a8d8d4
7
- data.tar.gz: 3c06dd06c7352f6590cf833361dfd2886abb42445989fa5c30e8307cebc63c35db49b646e1768b85e4a40c4c7c71005d78caef1a642393cf5c76e5dc6bd58fe0
6
+ metadata.gz: df18566c9678966e994a92564d8500c64b95abc6f33af4272004be45a9cd7490b41a43b2f67d6c069c872c14c7ce077e42ce3be153ef4694ccb154511ebb8fb3
7
+ data.tar.gz: 18983f0ed77e920a59d03367a083918eef9eae1a596e3aea9e2f3cf7a986af0e1c89dec3ca9f205e39fcd7442a867ca490e51588b7aea364847fe8881f1c8fb9
@@ -31,7 +31,8 @@ module Belt
31
31
  end
32
32
 
33
33
  def run
34
- validate!
34
+ return unless validate!
35
+
35
36
  models = parse_models
36
37
  if models.empty?
37
38
  puts "No models found in #{MODELS_DIR}/" unless @quiet
@@ -49,11 +50,11 @@ module Belt
49
50
  abort "Error: No models directory found at #{MODELS_DIR}/. " \
50
51
  'Run `belt generate model` to create your first model.'
51
52
  end
52
- return
53
+ return false
53
54
  end
54
- return if Dir.exist?(MODULE_DIR)
55
+ return true if Dir.exist?(MODULE_DIR)
55
56
 
56
- return if @quiet
57
+ return false if @quiet
57
58
 
58
59
  abort "Error: Module directory not found at #{MODULE_DIR}/.\n" \
59
60
  'Run `belt new` to create a project with the correct structure.'
data/lib/belt/cli.rb CHANGED
@@ -53,6 +53,9 @@ module Belt
53
53
 
54
54
  TERRAFORM_ACTIONS = Belt::CLI::TerraformCommand::ACTIONS
55
55
 
56
+ # Commands that can run without being inside a Belt project
57
+ STANDALONE_COMMANDS = %w[new version --version -v doctor].freeze
58
+
56
59
  def self.start(args)
57
60
  command = args.shift
58
61
 
@@ -61,17 +64,11 @@ module Belt
61
64
  exit 1
62
65
  end
63
66
 
67
+ # For project-level commands, find and chdir to the project root
68
+ ensure_project_root!(command) unless STANDALONE_COMMANDS.include?(command)
69
+
64
70
  # `belt destroy` is ambiguous: could be terraform destroy or belt destroy <generator>.
65
- # Route to DestroyCommand if the first arg is a known generator or help flag.
66
- if command == 'destroy'
67
- if args.empty? || args.first =~ /\A-/
68
- # belt destroy --help → DestroyCommand help
69
- # belt destroy (no args) → terraform destroy (needs env)
70
- return DestroyCommand.run(args) if args.include?('--help') || args.include?('-h')
71
- elsif DestroyCommand::GENERATORS.include?(args.first) || GeneratorRegistry.generator_names.include?(args.first)
72
- return DestroyCommand.run(args)
73
- end
74
- end
71
+ return if command == 'destroy' && route_destroy_command(args)
75
72
 
76
73
  # Terraform shorthand: belt init wups, belt plan wups, belt apply wups, belt destroy wups
77
74
  return Belt::CLI::TerraformCommand.run(command, args) if TERRAFORM_ACTIONS.include?(command)
@@ -161,5 +158,46 @@ module Belt
161
158
  belt plugin new messaging # scaffold a belt-messaging style plugin gem
162
159
  USAGE
163
160
  end
161
+
162
+ def self.not_in_app_message(command)
163
+ <<~MSG
164
+ Could not find a Belt application. Run `belt #{command}` from within a Belt project directory, or create a new one:
165
+
166
+ belt new <app_name> Create a new Belt application
167
+ belt new <app_name> --frontend react With a React frontend
168
+ belt new <app_name> --domain myapp.com With a custom domain
169
+
170
+ Examples:
171
+ belt new blog
172
+ belt new my-api --frontend react
173
+ belt new shop --domain shop.example.com
174
+
175
+ See `belt new --help` for all options.
176
+ MSG
177
+ end
178
+
179
+ def self.ensure_project_root!(command)
180
+ if Belt.root?
181
+ Dir.chdir(Belt.root)
182
+ else
183
+ puts not_in_app_message(command)
184
+ exit 1
185
+ end
186
+ end
187
+
188
+ # Routes `belt destroy` to DestroyCommand when args indicate a generator.
189
+ # Returns true if handled, false to fall through to TerraformCommand.
190
+ def self.route_destroy_command(args) # rubocop:disable Naming/PredicateMethod
191
+ if args.empty? || args.first =~ /\A-/
192
+ if args.include?('--help') || args.include?('-h')
193
+ DestroyCommand.run(args)
194
+ return true
195
+ end
196
+ elsif DestroyCommand::GENERATORS.include?(args.first) || GeneratorRegistry.generator_names.include?(args.first)
197
+ DestroyCommand.run(args)
198
+ return true
199
+ end
200
+ false
201
+ end
164
202
  end
165
203
  end
data/lib/belt/root.rb CHANGED
@@ -9,8 +9,14 @@ module Belt
9
9
  @root = path
10
10
  end
11
11
 
12
+ def self.root?
13
+ !root.nil?
14
+ end
15
+
12
16
  # Resolves the path to routes.rb, checking config/ first then legacy paths.
13
17
  def self.routes_file
18
+ return nil unless root
19
+
14
20
  candidates = [
15
21
  File.join(root, 'config/routes.rb'),
16
22
  File.join(root, 'config/routes.tf.rb'),
@@ -21,6 +27,8 @@ module Belt
21
27
 
22
28
  # Resolves the path to contracts.rb, checking config/ first then legacy paths.
23
29
  def self.contracts_file
30
+ return nil unless root
31
+
24
32
  candidates = [
25
33
  File.join(root, 'config/contracts.rb'),
26
34
  File.join(root, 'config/contracts.tf.rb'),
@@ -37,6 +45,8 @@ module Belt
37
45
 
38
46
  # Resolves the lambda config directory.
39
47
  def self.lambda_config_dir
48
+ return nil unless root
49
+
40
50
  File.join(root, 'config/lambda')
41
51
  end
42
52
 
@@ -52,7 +62,7 @@ module Belt
52
62
 
53
63
  dir = parent
54
64
  end
55
- Dir.pwd
65
+ nil
56
66
  end
57
67
 
58
68
  private_class_method :detect_root
data/lib/belt/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Belt
4
- VERSION = '0.2.15'
4
+ VERSION = '0.2.16'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: belt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.15
4
+ version: 0.2.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stowzilla