brut 0.21.0.pre.2 → 0.21.0.pre.3

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: '049e10b89cc1f9493bdac64fcdf569064de7458a36757a57681c5de5beec2fbe'
4
- data.tar.gz: 66dfee5973159e43bee8f1fe9a43efba162a3835df4a4fa7772fabcffca1dfef
3
+ metadata.gz: e7d83ff98517963f25fc7bda801f0525203a946b11a69c7c95ea18a7790d74a8
4
+ data.tar.gz: b11d1fd32f24dd4a5b654541a1c4f26f4039d8b2a1f2dc804eb1dcf255ef4df1
5
5
  SHA512:
6
- metadata.gz: c1bb2e290674f713ef35fe6d91abf566e2076146d60307f4f5a75b2bb84d5927455d2b050c35608568f90c5aaa579eeeca7ca1241c2d370810f5c669b724b735
7
- data.tar.gz: b3fbfbf1ffb662a3813a5aa30743e385efaaae6e95d2d265dbdb989b7cf8ad3ef8e48e4bab07139d68f2b0d5d633477ae32347d82103323260b420e567d48a3e
6
+ metadata.gz: 91af7b2b9ee3bf7b5aff57c0f656c050b4a89d8aebd1e38e9413aadd8d1d6378454a295c93134e8b5b24d9277ecfdd8c6ae296d5f08fceb7993b22191324972b
7
+ data.tar.gz: e2b3a79d3b2de5963bdf2fb9e8a6f6ec50afc105d79f0ba24669bd9174aa9aad1ec6579d940e4d4f2bd39f6d292f1f00ad760857cb9ca1ef323caac2d7ddf7b6
@@ -247,6 +247,14 @@ class Brut::CLI::Apps::DB < Brut::CLI::Commands::BaseCommand
247
247
  execution_context.logger.without_stderr,
248
248
  self
249
249
  )
250
+ database_description = if Brut.container.project_env.production?
251
+ "production database"
252
+ else
253
+ Brut.container.database_url
254
+ end
255
+ puts theme.header.render("🏗 Applying migrations to #{database_description}")
256
+
257
+
250
258
  Sequel::Migrator.run(Brut.container.sequel_db_handle,migrations_dir)
251
259
  puts theme.success.render("✅ All migrations have been applied")
252
260
  0
@@ -263,12 +271,7 @@ class Brut::CLI::Apps::DB < Brut::CLI::Commands::BaseCommand
263
271
  ].join(" ")
264
272
  1
265
273
  rescue Sequel::DatabaseError => ex
266
- #if ex.cause.kind_of?(PG::UndefinedTable)
267
- # # ignoring - we are running migrations which will address this
268
- # 0
269
- #else
270
- raise ex
271
- #end
274
+ raise ex
272
275
  end
273
276
  end
274
277
 
@@ -276,15 +279,24 @@ class Brut::CLI::Apps::DB < Brut::CLI::Commands::BaseCommand
276
279
  def description = "Drop, re-create, and run migrations, effecitvely rebuilding the entire database"
277
280
  def default_rack_env = "development"
278
281
  def bootstrap? = false
279
- def initialize
280
- super([
282
+ def opts = [
283
+ [ "--seed", "Load seed data after rebuild" ]
284
+ ]
285
+ def commands(execution_context)
286
+ default_commands = [
281
287
  Drop.new,
282
288
  Create.new,
283
289
  Migrate.new,
284
- ])
290
+ ]
291
+ if execution_context.options.seed?
292
+ default_commands + [ Seed.new ]
293
+ else
294
+ default_commands
295
+ end
285
296
  end
286
297
  end
287
298
 
299
+ # XXX
288
300
 
289
301
  class Seed < Brut::CLI::Commands::BaseCommand
290
302
  def description = "Load seed data into the database"
@@ -310,7 +322,7 @@ class Brut::CLI::Apps::DB < Brut::CLI::Commands::BaseCommand
310
322
  puts theme.exception.render(" #{ex}".strip)
311
323
  puts [
312
324
  theme.error.render("You can re-load it using"),
313
- theme.code.render("brut db rebuild && brut db seed"),
325
+ theme.code.render("brut db rebuild --seed"),
314
326
  ].join(" ")
315
327
  1
316
328
  end
@@ -9,11 +9,8 @@ class Brut::CLI::Apps::Deploy < Brut::CLI::Commands::BaseCommand
9
9
  autoload :GitChecks, "brut/cli/apps/deploy/git_checks"
10
10
 
11
11
  def name = "deploy"
12
-
13
12
  def description = "Deploy your Brut-powered app to production"
14
13
 
15
- def default_rack_env = nil
16
-
17
14
  class Docker < Brut::CLI::Commands::BaseCommand
18
15
  def description = "Build one docker image to use for all commands in production"
19
16
  def opts = [
@@ -96,6 +93,7 @@ class Brut::CLI::Apps::Deploy < Brut::CLI::Commands::BaseCommand
96
93
  end
97
94
  end
98
95
  end
96
+ def default_rack_env = "development"
99
97
  def description = "Deploy to Heroku using container-based deployment"
100
98
  def opts = [
101
99
  [ "--build-only", "Only generate Dockerfiles and build images, do not deploy" ],
@@ -84,6 +84,8 @@ class Brut::CLI::Apps::New::App < Brut::CLI::Commands::BaseCommand
84
84
  ],
85
85
  ]
86
86
 
87
+ def default_rack_env = nil
88
+
87
89
  def run
88
90
 
89
91
  app_name = argv[0]
@@ -262,6 +264,7 @@ class Brut::CLI::Apps::New::App < Brut::CLI::Commands::BaseCommand
262
264
 
263
265
  class Segment < Brut::CLI::Commands::BaseCommand
264
266
  def description = "Add a segement to your app to provide additional pre-configured functionality"
267
+ def default_rack_env = nil
265
268
 
266
269
  def args_description = "segment_name"
267
270
 
@@ -50,20 +50,26 @@ Runs all non end-to-end tests for the app, or runs a subset of non-end-to-end te
50
50
  def rebuild_after_by_default? = false
51
51
 
52
52
  def run
53
- if options.rebuild?(default: rebuild_by_default?)
54
- puts "Rebuilding test database schema"
55
- Bundler.with_unbundled_env do
56
- system! "brut db rebuild --env=test"
57
- end
58
- end
53
+ rebuild_db(before_or_after: :before)
59
54
  run_tests
60
- if options.rebuild_after?(default: rebuild_after_by_default?)
61
- puts "Re-Rebuilding test database schema"
55
+ rebuild_db(before_or_after: :after)
56
+ 0
57
+ end
58
+
59
+ def rebuild_db(before_or_after:)
60
+ option, default, verb = if before_or_after == :before
61
+ [ :rebuild?, :rebuild_by_default?, "Rebuilding" ]
62
+ elsif before_or_after == :after
63
+ [ :rebuild_after?, :rebuild_after_by_default?, "Re-rebuilding" ]
64
+ else
65
+ bug!("before_or_after must be :before or :after")
66
+ end
67
+ if options.send(option, default: self.send(default))
68
+ puts "#{verb} testing datbase"
62
69
  Bundler.with_unbundled_env do
63
70
  system! "brut db rebuild --env=test"
64
71
  end
65
72
  end
66
- 0
67
73
  end
68
74
 
69
75
  private
@@ -100,9 +106,8 @@ Runs all non end-to-end tests for the app, or runs a subset of non-end-to-end te
100
106
  Runs all end-to-end tests for the app, or runs a subset of end-to-end tests using RSpec-style syntax. This will run bin/test-server first, so if that fails for some reason, no tests are run.
101
107
  }
102
108
 
103
- private
104
-
105
- def run_tests
109
+ def run
110
+ rebuild_db(before_or_after: :before)
106
111
  require "brut/spec_support/e2e_test_server"
107
112
  test_server = Brut::SpecSupport::E2ETestServer.new(
108
113
  bin_dir: Brut.container.project_root / "bin",
@@ -110,12 +115,15 @@ Runs all end-to-end tests for the app, or runs a subset of end-to-end tests usin
110
115
  )
111
116
  begin
112
117
  test_server.start
113
- super
118
+ run_tests
114
119
  ensure
115
120
  test_server.stop
121
+ rebuild_db(before_or_after: :after)
116
122
  end
123
+ 0
117
124
  end
118
125
  end
126
+
119
127
  class Js < Brut::CLI::Commands::BaseCommand
120
128
  def default_rack_env = "development"
121
129
  def description = "Run JavaScript unit tests"
@@ -130,7 +138,7 @@ Runs all end-to-end tests for the app, or runs a subset of end-to-end tests usin
130
138
  options.set_default(:"build-assets", true)
131
139
  if options.build_assets?
132
140
  Bundler.with_unbundled_env do
133
- system!({ "RACK_ENV" => "test" }, "brut build-assets all")
141
+ system!("brut build-assets all --env=test")
134
142
  end
135
143
  end
136
144
  execution_context.executor.system!({ "NODE_DISABLE_COLORS" => "1" },"npx mocha #{Brut.container.js_specs_dir} --no-color --extension 'spec.js' --recursive")
@@ -46,18 +46,20 @@ class Brut::CLI::Commands::BaseCommand
46
46
  def bootstrap? = false
47
47
 
48
48
  # The default `RACK_ENV` to use for this command. This value is used when no `RACK_ENV` is present in the UNIX environment
49
- # and when `--env` has not been used on the command line. Do note that setting this in an app or parent command does
50
- # not translate to the subcommands.
49
+ # and when `--env` has not been used on the command line. This only applies to the command where
50
+ # the method is defined and its subclasses. It **does not** apply to subcommands of this command.
51
+ #
52
+ # The default value is 'development', mostly because a default of `nil` produces a strange error
53
+ # message if your intention was to load Brut configuration.
51
54
  #
52
55
  # @return [String|nil] If nil, Brut configuration will not be loaded and the command will run more or less as if it were a plain
53
56
  # Ruby script. If a `String`, this value will be set as the `RACK_ENV` if it's not been otherwise specified.
54
- def default_rack_env = nil
57
+ def default_rack_env = "development"
55
58
 
56
59
  # @return [String] description of this command for use in help output
57
60
  def description = ""
58
61
 
59
- # Returns a more detaile description of the command. This can includes paragraphs which will be maintained, however
60
- # any additional formatting is not rendered or used.
62
+ # Returns a more detaile description of the command. This can includes paragraphs (which will be maintained in the output), however any additional formatting is not rendered or used.
61
63
  def detailed_description = nil
62
64
 
63
65
  # @return [String] description of the arguments this command accepts. Used for documentation only.
@@ -5,8 +5,12 @@ class Brut::CLI::Commands::CompoundCommand < Brut::CLI::Commands::BaseCommand
5
5
  # Create the compound command with the given list of commands. Note that these
6
6
  # commands will be executed with *this* commands `Brut::CLI::Commands::ExecutionContext`, so these commands
7
7
  # should all be able to work with whatever command line arguments and `argv` would be provided.
8
- def initialize(commands)
9
- @commands = commands
8
+ #
9
+ # @param [Array<Brut::CLI::Commands::BaseCommand>|nil] The list of commands to run when
10
+ # this command is executed. If nil, it is assumed you have overriden `commands` to
11
+ # provide the list dynamically.
12
+ def initialize(commands=nil)
13
+ @commands = commands || []
10
14
  end
11
15
 
12
16
  # Overrides the parent class to call each command in order. Note that if you subclass this class, **`run` is
@@ -14,7 +18,7 @@ class Brut::CLI::Commands::CompoundCommand < Brut::CLI::Commands::BaseCommand
14
18
  # methods on the passed `execution_context`. Methods like `puts`, `system!`, and `options` **will not work** here
15
19
  # since they assume an ivar named `@execution_context` has been set.
16
20
  def execute(execution_context)
17
- @commands.each do |command|
21
+ commands(execution_context).each do |command|
18
22
  execute_result = Brut::CLI::ExecuteResult.new do
19
23
  delegate_to_command(command,execution_context)
20
24
  end
@@ -24,4 +28,16 @@ class Brut::CLI::Commands::CompoundCommand < Brut::CLI::Commands::BaseCommand
24
28
  end
25
29
  0
26
30
  end
31
+
32
+ # Protocol for which commands to run. You can override this to dynamically set which
33
+ # commands are run based on the parsed command line. Note that you must call
34
+ # methods like `puts` or `system!` **on the passed `execution_context`**. Do not
35
+ # call them directly.
36
+ #
37
+ # @param [Brut::CLI::ExecutionContext] execution_context the execution context for this
38
+ # command. You can use this to examine e.g. CLI options to determine which commands
39
+ # to return.
40
+ #
41
+ # @return [Array<Brut::CLI::Commands::BaseCommand>]
42
+ def commands(execution_context) = @commands
27
43
  end
@@ -1,5 +1,6 @@
1
1
  class Brut::CLI::Commands::Help < Brut::CLI::Commands::BaseCommand
2
2
  def description = "Get help for the app or a command"
3
+ def default_rack_env = nil
3
4
  attr_accessor :option_parser
4
5
 
5
6
  def initialize(command,option_parser)
@@ -1,5 +1,6 @@
1
1
  class Brut::CLI::Commands::HelpInMarkdown < Brut::CLI::Commands::BaseCommand
2
2
  def description = "Get help for the app or a command, in Markdown"
3
+ def default_rack_env = "development"
3
4
  attr_accessor :option_parser
4
5
 
5
6
  def initialize(command,option_parser)
@@ -106,13 +106,7 @@ class Brut::CLI::ParsedCommandLine
106
106
  @argv = remaining_argv
107
107
  @options = Brut::CLI::Options.new(options)
108
108
  if !@options.log_level?
109
- if @options.verbose? || @options.debug?
110
- @options[:'log-level'] = "debug"
111
- elsif @options.quiet?
112
- @options[:'log-level'] = "error"
113
- else
114
- @options[:'log-level'] = "info"
115
- end
109
+ @options[:'log-level'] = "info"
116
110
  end
117
111
  if !@options[:'log-file']
118
112
  log_file_path = if env["XDG_STATE_HOME"]
@@ -128,9 +122,6 @@ class Brut::CLI::ParsedCommandLine
128
122
  else
129
123
  @options[:'log-file'] = Pathname(@options[:'log-file'])
130
124
  end
131
- if @options[:'log-stdout'].nil?
132
- @options[:'log-stdout'] = @options.verbose? || @options.debug?
133
- end
134
125
  rescue => ex
135
126
  @command = if env["BRUT_DEBUG"] == "true"
136
127
  Brut::CLI::Commands::RaiseError.new(ex)
@@ -152,8 +143,6 @@ private
152
143
  "Project environment, e.g. test, development, production. Default depends on the command")
153
144
  opts.on("--log-level=LOG_LEVEL", [ "debug", "info", "warn", "error", "fatal" ],
154
145
  "Log level, which should be debug, info, warn, error, or fatal. Defaults to error")
155
- opts.on("--debug", "--verbose", "Set log level to debug, and show log messages on stdout")
156
- opts.on("--quiet", "Set log level to error")
157
146
  opts.on("--log-file=FILE",
158
147
  "Path to a file where log messages are written. Defaults to $XDG_CACHE_HOME/brut/logs/#{app_name}.log")
159
148
  opts.on("--[no-]log-stdout", "Log messages to stdout in addition to the log file")
@@ -77,17 +77,13 @@ class Brut::CLI::Runner
77
77
  private
78
78
 
79
79
  def load_unix_environment!(env, parsed_command_line)
80
- if env["RACK_ENV"]
81
- if parsed_command_line.project_environment
82
- @stderr.puts "RACK_ENV is set in the environment, which supercedes the command line, --env ignored"
83
- end
84
- else
85
- env["RACK_ENV"] = if parsed_command_line.project_environment
86
- parsed_command_line.project_environment.to_s
87
- else
88
- parsed_command_line.command.default_rack_env
89
- end
90
- end
80
+ env["RACK_ENV"] = if parsed_command_line.project_environment
81
+ parsed_command_line.project_environment.to_s
82
+ elsif env["RACK_ENV"]
83
+ env["RACK_ENV"]
84
+ else
85
+ parsed_command_line.command.default_rack_env
86
+ end
91
87
 
92
88
  rack_env = RichString.from_string(env["RACK_ENV"])
93
89
 
@@ -135,9 +131,9 @@ private
135
131
  if env["RACK_ENV"]
136
132
  log_level = env["LOG_LEVEL"]
137
133
 
138
- if !parsed_command_line.options.verbose? && !parsed_command_line.options.debug?
139
- env["LOG_LEVEL"] = "warn"
140
- end
134
+ # Prevent lots of stuff from logging just
135
+ # because it was required
136
+ env["LOG_LEVEL"] = "warn"
141
137
 
142
138
  require "#{@project_root}/app/bootstrap"
143
139
  bootstrap = Bootstrap.new
@@ -147,6 +143,7 @@ private
147
143
  bootstrap.configure_only!
148
144
  end
149
145
 
146
+ # restore the log level
150
147
  env["LOG_LEVEL"] = log_level
151
148
  end
152
149
  end
data/lib/brut/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Brut
2
2
  # @!visibility private
3
- VERSION = "0.21.0.pre.2"
3
+ VERSION = "0.21.0.pre.3"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brut
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.21.0.pre.2
4
+ version: 0.21.0.pre.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Bryant Copeland