lux-hammer 0.2.1 → 0.2.2

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: 17ad95331316a0cd95554605d58b2a7dce64f9db9d6adc997b34cf5f3b1e2b1a
4
- data.tar.gz: 633ad47b777e68b848f11552e5345d5b468e01a0fa27a273dc6551aac7d18af1
3
+ metadata.gz: 9b973a2becedf10ed4247fce46d195f07619c6f6b9bf56f41464b57764733716
4
+ data.tar.gz: a1ffdc8fa9b19f47599a3e930181fa1972095872db4f92740308cf393090bfcd
5
5
  SHA512:
6
- metadata.gz: '0568fccc6f143b0671166a08c1853a3f682bf2c4c5488791fa7d46e1c4d8b3cc311ae29a016e9cf9a93f2cc31a577a551af72f0f4754cc9e9bd3adb66c5f6731'
7
- data.tar.gz: bf5e04d1e37e50f138c7c14079b889018f85bda195dad8676df4f634a37fe62414a1511a451aacb08f1e0860651426d8a7bca78cf3bad35b1fbf3dc137423438
6
+ metadata.gz: 55e093ed6cc2ed08349fdfd9296360153b2d0cb4763b57546e4e9453657e0da7e74608179b70946d6600499624b0cac1c57017208a91143d3eba6917a1cef976
7
+ data.tar.gz: 3401f9c5defba4419e40c571cfcab4869ceb408dbcf8a88d9bab98aea2760ad810ceee02feaa31f78b661849e88b1ecb7c5e63ad3e930ed3baa371637d15f20b
data/.version CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
data/README.md CHANGED
@@ -844,18 +844,18 @@ end
844
844
 
845
845
  ```sh
846
846
  $ hammer
847
- Usage: demo COMMAND [ARGS]
847
+ Usage: hammer COMMAND [ARGS]
848
848
 
849
849
  Commands:
850
- demo build # Build the project
851
- demo deploy (alt: ship) # Deploy to URL
850
+ hammer build # Build the project
851
+ hammer deploy (alt: ship) # Deploy to URL
852
852
 
853
853
  db:
854
- demo db:migrate (alt: m) # Run pending migrations
854
+ hammer db:migrate (alt: m) # Run pending migrations
855
855
 
856
856
  db:users:
857
- demo db:users:list # List users
858
- demo db:users:create # Create a user
857
+ hammer db:users:list # List users
858
+ hammer db:users:create # Create a user
859
859
 
860
860
  $ hammer build prod -v
861
861
  building prod
@@ -872,17 +872,17 @@ $ hammer db:users:create --email=dino@example.com --admin
872
872
  create dino@example.com admin=true
873
873
 
874
874
  $ hammer db # bare namespace shows its contents
875
- Usage: demo db:COMMAND [ARGS]
875
+ Usage: hammer db:COMMAND [ARGS]
876
876
 
877
877
  Commands:
878
- demo db:migrate (alt: m) # Run pending migrations
878
+ hammer db:migrate (alt: m) # Run pending migrations
879
879
 
880
880
  users:
881
- demo db:users:list # List users
882
- demo db:users:create # Create a user
881
+ hammer db:users:list # List users
882
+ hammer db:users:create # Create a user
883
883
 
884
884
  $ hammer db:users:create -h
885
- Usage: demo db:users:create EMAIL [OPTIONS]
885
+ Usage: hammer db:users:create EMAIL [OPTIONS]
886
886
  Create a user
887
887
 
888
888
  Options:
@@ -7,10 +7,6 @@ class Hammer
7
7
  @klass = klass
8
8
  end
9
9
 
10
- def program(name)
11
- @klass.program_name(name)
12
- end
13
-
14
10
  def define(name, &block)
15
11
  @klass.define(name, &block)
16
12
  end
data/lib/lux-hammer.rb CHANGED
@@ -11,8 +11,6 @@ require_relative 'hammer/command_builder'
11
11
  # Class DSL:
12
12
  #
13
13
  # class MyCli < Hammer
14
- # program_name 'mycli'
15
- #
16
14
  # define :build do
17
15
  # desc 'Build the project'
18
16
  # example 'build -v --env=prod'
@@ -29,7 +27,6 @@ require_relative 'hammer/command_builder'
29
27
  # Block DSL is identical, just inside `Hammer.run`:
30
28
  #
31
29
  # Hammer.run(ARGV) do
32
- # program 'inline'
33
30
  # define :hello do
34
31
  # desc 'Greet someone'
35
32
  # opt :loud, type: :boolean, alias: :l
@@ -101,15 +98,17 @@ class Hammer
101
98
  @pending_needs = []
102
99
  end
103
100
 
104
- def program_name(name = nil)
105
- @program_name = name if name
106
- @program_name || default_program_name
101
+ # Resolved lazily on first read and memoized, so callers that need the
102
+ # cwd-relative form (see `default_program_name`) can warm the cache
103
+ # before chdir-ing elsewhere.
104
+ def program_name
105
+ @program_name ||= default_program_name
107
106
  end
108
107
 
109
- # Default shown in help/usage when `program_name` is not set:
110
- # the invocation path relative to cwd if the script lives inside it
111
- # (e.g. `bin/foo` when invoked from the project root), otherwise the
112
- # basename (e.g. `lux` for a globally installed bin in PATH).
108
+ # Program name shown in help/usage: the invocation path relative to cwd
109
+ # if the script lives inside it (e.g. `bin/foo` when invoked from the
110
+ # project root), otherwise the basename (e.g. `lux` for a globally
111
+ # installed bin in PATH).
113
112
  def default_program_name
114
113
  prog = $PROGRAM_NAME
115
114
  return File.basename(prog) unless prog.include?('/')
@@ -159,8 +158,8 @@ class Hammer
159
158
  end
160
159
 
161
160
  # Open a namespace (group of commands). Everything inside the block
162
- # (define, nested namespace, program_name override, ...) belongs to
163
- # that namespace, evaluated against an anonymous Hammer subclass.
161
+ # (define, nested namespace, ...) belongs to that namespace, evaluated
162
+ # against an anonymous Hammer subclass.
164
163
  #
165
164
  # namespace :db do
166
165
  # define :migrate do ... end
@@ -175,9 +174,10 @@ class Hammer
175
174
  # Parent link, so `before` hooks defined further up the namespace
176
175
  # tree can be collected and run outer -> inner before a command.
177
176
  sub.instance_variable_set(:@parent, self)
178
- # Inherit program_name so help banners show "myapp ns:cmd", not
179
- # whichever binary the namespace class fell back to.
180
- sub.program_name(program_name) if @program_name
177
+ # Share the parent's resolved program_name so help banners show
178
+ # "myapp ns:cmd" with the same prefix everywhere - and so the value
179
+ # captured pre-chdir (see `Hammer.cli`) survives into nested classes.
180
+ sub.instance_variable_set(:@program_name, program_name)
181
181
  sub.class_eval(&block) if block
182
182
  @namespaces[name.to_s] = sub
183
183
  end
@@ -548,8 +548,8 @@ class Hammer
548
548
 
549
549
  # ----- block DSL -----------------------------------------------------
550
550
 
551
- # Define and run a CLI inline. Inside the block use `program`,
552
- # `define :name do ... end`, and `namespace`.
551
+ # Define and run a CLI inline. Inside the block use
552
+ # `define :name do ... end`, `namespace`, and `load`.
553
553
  #
554
554
  # Without a block: load ./Hammerfile if it exists, otherwise
555
555
  # auto-discover *_hammer.rb under Dir.pwd, then dispatch ARGV.
@@ -577,8 +577,6 @@ class Hammer
577
577
  Shell.print_error "no Hammerfile found in #{Dir.pwd} or any parent directory"
578
578
  Shell.say "create one - example:"
579
579
  Shell.say <<~RUBY
580
- program 'mycli'
581
-
582
580
  define :hello do
583
581
  desc 'say hello'
584
582
  proc { |opts| say "hello \#{opts[:args].first || 'world'}", :green }
@@ -589,8 +587,8 @@ class Hammer
589
587
 
590
588
  klass = Class.new(Hammer)
591
589
  # Resolve before chdir so paths like `bin/foo` stay relative to the
592
- # cwd the user actually invoked from.
593
- klass.program_name(klass.default_program_name)
590
+ # cwd the user actually invoked from. `program_name` memoizes.
591
+ klass.program_name
594
592
 
595
593
  # chdir into the Hammerfile's directory for the entire run so commands
596
594
  # operate on the project root (Rake-style).
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lux-hammer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dino Reic