locd 0.1.5 → 0.1.6

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
  SHA1:
3
- metadata.gz: 9c5204f4e2f4bcd01e4af0c6532c1505b117cadd
4
- data.tar.gz: 7268adf8c6b457a0ea347fede69c923202baba32
3
+ metadata.gz: 21e58280d1931b02f58ba82b427ad422db7ff696
4
+ data.tar.gz: 47f847da55d407db080e0b999cb6882898d12940
5
5
  SHA512:
6
- metadata.gz: e6d3f99a7a47678345bdfd2785c56e48cd291b026a9c215be9bfdd6117fafbad96cd2d4a65225b1b3feb48f04219c9d8b31ddd5a8c0a10f6ef3ebd4eb4c83364
7
- data.tar.gz: '029dae728f2d37236167b21e6ff03c35289cace83e38d18a59fea4f1f71f66a2dfd274e1f1a87eebb1bcaa88106a67acf7fd78606459816288f3d822ba6010a5'
6
+ metadata.gz: cae7b8aaf1e7e03cc802ae6155e04a388bb7269203e5c002ea54e0de7667130e33149493df5b0f631c7dfcd2aaae1667cf2f87bfd2cf3021d4966cd4493f5bf5
7
+ data.tar.gz: d994ec75280c5e302844f119097f2ced9802ba5d558f57488eb661092548dca4be7a542075b3afe08bae82556c19693612bc6480ec94bc1cfc929cb09cef23c3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
1
+ 0.1.6
data/exe/locd CHANGED
@@ -6,10 +6,10 @@ require 'locd'
6
6
 
7
7
  # Setup logging *before* including {Locd::CLI} so that we can get
8
8
  # trace/debug output from that setup if enabled via ENV vars
9
- NRSER::Logging.setup! application: 'Locd', dest: $stderr, sync: true
9
+ NRSER::Log.setup_for_cli! application: 'Locd', dest: $stderr, sync: true
10
10
 
11
11
  # Logger for this file
12
- logger = SemanticLogger[__FILE__]
12
+ logger = NRSER::Log[__FILE__]
13
13
 
14
14
  require 'locd/cli'
15
15
 
@@ -29,12 +29,6 @@ require 'locd/agent'
29
29
  require 'locd/proxy'
30
30
 
31
31
 
32
- # Refinements
33
- # =======================================================================
34
-
35
- using NRSER
36
-
37
-
38
32
  # Definitions
39
33
  # =======================================================================
40
34
 
@@ -57,7 +51,7 @@ module Locd
57
51
  # ============================================================================
58
52
 
59
53
  # Add {.logger} and {#logger} methods
60
- include NRSER::Logging::Mixin
54
+ include NRSER::Log::Mixin
61
55
 
62
56
 
63
57
  # Module Methods
@@ -18,7 +18,7 @@ require 'fileutils'
18
18
  # Refinements
19
19
  # =======================================================================
20
20
 
21
- using NRSER
21
+ require 'nrser/refinements/types'
22
22
  using NRSER::Types
23
23
 
24
24
 
@@ -51,7 +51,7 @@ class Locd::Agent
51
51
  # ==========================================================================
52
52
 
53
53
  # Add {.logger} and {#logger} methods
54
- include NRSER::Logging::Mixin
54
+ include NRSER::Log::Mixin
55
55
 
56
56
  # Make agents sortable by label
57
57
  include Comparable
@@ -264,6 +264,20 @@ class Locd::Agent
264
264
  end
265
265
 
266
266
 
267
+ # Does this agent exist?
268
+ #
269
+ # @param [String] label
270
+ # Agent's label (AKA name AKA domain).
271
+ #
272
+ # @return [Boolean]
273
+ #
274
+ def self.exists? label
275
+ File.exists? plist_abs_path( label )
276
+ end # .exists?
277
+
278
+ singleton_class.send :alias_method, :exist?, :exists?
279
+
280
+
267
281
  # All {Locd::Agent} that are instances of `self`.
268
282
  #
269
283
  # So, when invoked through {Locd::Agent.all} returns all agents.
@@ -633,6 +647,29 @@ class Locd::Agent
633
647
  end # .add
634
648
 
635
649
 
650
+ # Pretty much what the name says.
651
+ #
652
+ # @see .add
653
+ # @see #update
654
+ #
655
+ # @param [String] label
656
+ # Agent's label (AKA name AKA domain).
657
+ #
658
+ # @param **values
659
+ # Agent properties.
660
+ #
661
+ # @return [Array<((:add | :update), Locd::Agent)]
662
+ # Whether the agent was added or updated, followed by the agent instance.
663
+ #
664
+ def self.add_or_update label:, **values
665
+ if exists? label
666
+ [:update, get( label ).update( **values )]
667
+ else
668
+ [:add, add( label: label, **values )]
669
+ end
670
+ end
671
+
672
+
636
673
  # Attributes
637
674
  # ============================================================================
638
675
 
@@ -4,7 +4,7 @@
4
4
  # Refinements
5
5
  # =======================================================================
6
6
 
7
- using NRSER
7
+ require 'nrser/refinements/types'
8
8
  using NRSER::Types
9
9
 
10
10
 
@@ -18,7 +18,7 @@ require 'fileutils'
18
18
  # Refinements
19
19
  # =======================================================================
20
20
 
21
- using NRSER
21
+ require 'nrser/refinements/types'
22
22
  using NRSER::Types
23
23
 
24
24
 
@@ -18,7 +18,7 @@ require 'fileutils'
18
18
  # Refinements
19
19
  # =======================================================================
20
20
 
21
- using NRSER
21
+ require 'nrser/refinements/types'
22
22
  using NRSER::Types
23
23
 
24
24
 
@@ -18,7 +18,7 @@ require 'fileutils'
18
18
  # Refinements
19
19
  # =======================================================================
20
20
 
21
- using NRSER
21
+ require 'nrser/refinements/types'
22
22
  using NRSER::Types
23
23
 
24
24
 
@@ -126,7 +126,8 @@ class Locd::Agent::Site < Locd::Agent
126
126
  keep_alive: false,
127
127
  run_at_load: false,
128
128
  port: nil,
129
- bind: Locd.config[:site, :bind]
129
+ bind: Locd.config[:site, :bind],
130
+ open_path: '/'
130
131
  # Allocate a port if one was not provided
131
132
  port = if port.nil?
132
133
  Locd::Proxy.allocate_port
@@ -135,6 +136,8 @@ class Locd::Agent::Site < Locd::Agent
135
136
  port.to_i
136
137
  end
137
138
 
139
+ open_path = "/#{ path }" unless open_path.start_with? '/'
140
+
138
141
  super cmd_template: cmd_template,
139
142
  label: label,
140
143
  workdir: workdir,
@@ -143,7 +146,8 @@ class Locd::Agent::Site < Locd::Agent
143
146
  run_at_load: run_at_load,
144
147
  # Extras specific to {Locd::Agent::Site}:
145
148
  port: port,
146
- bind: bind
149
+ bind: bind,
150
+ open_path: open_path
147
151
  end # .create_plist_data
148
152
 
149
153
 
@@ -163,10 +167,15 @@ class Locd::Agent::Site < Locd::Agent
163
167
  end
164
168
 
165
169
 
170
+ def open_path
171
+ config['open_path'] || '/'
172
+ end
173
+
174
+
166
175
  # @return [String]
167
176
  # The URL the agent can be reached at through the proxy.
168
177
  def url
169
- "http://#{ label }:#{ Locd::Proxy.port }"
178
+ "http://#{ label }:#{ Locd::Proxy.port }#{ open_path }"
170
179
  end
171
180
 
172
181
  # @!endgroup Instance Methods: Attribute Readers
@@ -4,7 +4,7 @@
4
4
  # Refinements
5
5
  # =======================================================================
6
6
 
7
- using NRSER
7
+ require 'nrser/refinements/types'
8
8
  using NRSER::Types
9
9
 
10
10
 
@@ -6,4 +6,5 @@ require_relative './command/site'
6
6
  require_relative './command/job'
7
7
  require_relative './command/proxy'
8
8
  require_relative './command/rotate_logs'
9
+ require_relative './command/project'
9
10
  require_relative './command/main'
@@ -16,7 +16,7 @@
16
16
  # Refinements
17
17
  # =======================================================================
18
18
 
19
- using NRSER
19
+ require 'nrser/refinements/types'
20
20
  using NRSER::Types
21
21
 
22
22
 
@@ -339,6 +339,9 @@ class Locd::CLI::Command::Agent < Locd::CLI::Command::Base
339
339
 
340
340
  def rm pattern
341
341
  kwds = option_kwds :logs
342
+
343
+ logger.debug "kwds", kwds
344
+
342
345
  find_multi!( pattern ).each { |agent| agent.remove **kwds }
343
346
  end
344
347
 
@@ -18,7 +18,7 @@ require 'thor'
18
18
  # Refinements
19
19
  # =======================================================================
20
20
 
21
- using NRSER
21
+ require 'nrser/refinements/types'
22
22
  using NRSER::Types
23
23
 
24
24
 
@@ -5,7 +5,7 @@
5
5
  # Refinements
6
6
  # =======================================================================
7
7
 
8
- using NRSER
8
+ require 'nrser/refinements/types'
9
9
  using NRSER::Types
10
10
 
11
11
 
@@ -16,7 +16,7 @@
16
16
  # Refinements
17
17
  # =======================================================================
18
18
 
19
- using NRSER
19
+ require 'nrser/refinements/types'
20
20
  using NRSER::Types
21
21
 
22
22
 
@@ -128,7 +128,7 @@ class Locd::CLI::Command::Main < Locd::CLI::Command::Base
128
128
  }.to_sym
129
129
  end
130
130
 
131
- NRSER::Logging.level = level unless level.nil?
131
+ NRSER::Log.level = level unless level.nil?
132
132
 
133
133
  if levels = Locd.config[:log, :levels]
134
134
  levels.each do |name, level|
@@ -151,8 +151,8 @@ class Locd::CLI::Command::Main < Locd::CLI::Command::Base
151
151
  end
152
152
  end
153
153
 
154
- if [:trace, :debug].include? NRSER::Logging.level
155
- logger.send NRSER::Logging.level, "Hello! We about to start the show..."
154
+ if [:trace, :debug].include? NRSER::Log.level
155
+ logger.send NRSER::Log.level, "Hello! We about to start the show..."
156
156
  end
157
157
  end
158
158
 
@@ -211,4 +211,10 @@ class Locd::CLI::Command::Main < Locd::CLI::Command::Base
211
211
  subcommand 'rotate_logs',
212
212
  Locd::CLI::Command::RotateLogs
213
213
 
214
+
215
+ desc 'project SUBCOMMAND...',
216
+ 'Manage Agent definitions for projects'
217
+ subcommand 'project',
218
+ Locd::CLI::Command::Project
219
+
214
220
  end # class Locd::CLI::Command::Main
@@ -0,0 +1,90 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+
5
+ # Refinements
6
+ # =======================================================================
7
+
8
+ require 'nrser/refinements/types'
9
+ using NRSER::Types
10
+
11
+
12
+ # Definitions
13
+ # =======================================================================
14
+
15
+ # Manage Agent definitions attached to projects.
16
+ #
17
+ module Locd
18
+ module CLI
19
+ module Command
20
+ class Project < Base
21
+
22
+ # Instance Methods
23
+ # ========================================================================
24
+
25
+ # @!group Command Instance Methods
26
+ # --------------------------------------------------------------------------
27
+
28
+ desc 'load',
29
+ "Load project Agent definitions"
30
+
31
+ option :file,
32
+ aliases: [ 'f' ],
33
+ type: :string,
34
+ default: './dev/locd.yaml'
35
+ def load
36
+
37
+ file_path = options[:file].to_pn.expand_path
38
+
39
+ unless file_path.file?
40
+ raise "Definition file not found at `#{ file_path }`"
41
+ end
42
+
43
+ defs = YAML.load( file_path.read ).with_indifferent_access
44
+
45
+ t.hash_(
46
+ keys: t.in(%w{agents sites jobs}),
47
+ ).check! defs
48
+
49
+ {
50
+ agents: Locd::Agent,
51
+ sites: Locd::Agent::Site,
52
+ jobs: Locd::Agent::Job,
53
+ }.each do |key, agent_class|
54
+ if defs.key? key
55
+ logger.info "Adding or updating #{ key }..."
56
+
57
+ defs[key].each do |label, values|
58
+ logger.info payload: {
59
+ values: values,
60
+ options: values.to_options,
61
+ }
62
+
63
+ method, agent = agent_class.add_or_update \
64
+ label: label,
65
+ **values.
66
+ map { |key, value|
67
+ key = key.gsub '-', '_'
68
+ if key == 'cmd_template'
69
+ value = value.squish
70
+ end
71
+
72
+ [ key, value ]
73
+ }.
74
+ to_h.
75
+ to_options
76
+
77
+ action = t.match method,
78
+ :add, 'added',
79
+ :update, 'updated'
80
+
81
+ logger.info "Agent `#{ label }` #{ action }"
82
+ end # each label, values
83
+ end # if defs.key? key
84
+ end # each key, agent_class
85
+
86
+ end
87
+
88
+ # @!endgroup Command Instance Methods # ************************************
89
+
90
+ end; end; end; end # class Locd::CLI::Command::Site
@@ -18,7 +18,7 @@ require 'thor'
18
18
  # Refinements
19
19
  # =======================================================================
20
20
 
21
- using NRSER
21
+ require 'nrser/refinements/types'
22
22
  using NRSER::Types
23
23
 
24
24
 
@@ -18,7 +18,7 @@ require 'thor'
18
18
  # Refinements
19
19
  # =======================================================================
20
20
 
21
- using NRSER
21
+ require 'nrser/refinements/types'
22
22
  using NRSER::Types
23
23
 
24
24
 
@@ -5,7 +5,7 @@
5
5
  # Refinements
6
6
  # =======================================================================
7
7
 
8
- using NRSER
8
+ require 'nrser/refinements/types'
9
9
  using NRSER::Types
10
10
 
11
11
 
@@ -16,7 +16,7 @@
16
16
  # Refinements
17
17
  # =======================================================================
18
18
 
19
- using NRSER
19
+ require 'nrser/refinements/types'
20
20
  using NRSER::Types
21
21
 
22
22
 
@@ -51,7 +51,6 @@ class Locd::CLI::Table
51
51
  # ============================================================================
52
52
 
53
53
  include Enumerable
54
- include NRSER::Ext::Enumerable
55
54
 
56
55
 
57
56
  # Classes
@@ -10,6 +10,9 @@ require 'pathname'
10
10
 
11
11
  # Deps
12
12
  # -----------------------------------------------------------------------
13
+ require 'nrser'
14
+ require 'nrser/core_ext/object'
15
+
13
16
 
14
17
  # Project / Package
15
18
  # -----------------------------------------------------------------------
@@ -18,7 +21,7 @@ require 'pathname'
18
21
  # Refinements
19
22
  # =======================================================================
20
23
 
21
- using NRSER
24
+ require 'nrser/refinements/types'
22
25
  using NRSER::Types
23
26
 
24
27
 
@@ -1,10 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Refinements
4
- # =======================================================================
5
-
6
- using NRSER
7
-
8
3
 
9
4
  # Definitions
10
5
  # =======================================================================
@@ -1,10 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Refinements
4
- # =======================================================================
5
-
6
- using NRSER
7
-
8
3
 
9
4
  # Definitions
10
5
  # =======================================================================
@@ -17,7 +17,7 @@ require 'cmds'
17
17
  # Refinements
18
18
  # =======================================================================
19
19
 
20
- using NRSER
20
+ require 'nrser/refinements/types'
21
21
  using NRSER::Types
22
22
 
23
23
 
@@ -60,7 +60,7 @@ module Locd::Launchctl
60
60
  # ============================================================================
61
61
 
62
62
  # Add {.logger} method
63
- include NRSER::Logging::Mixin
63
+ include NRSER::Log::Mixin
64
64
 
65
65
 
66
66
  # Classes
@@ -18,7 +18,7 @@ require 'cmds'
18
18
  # Refinements
19
19
  # =======================================================================
20
20
 
21
- using NRSER
21
+ require 'nrser/refinements/types'
22
22
  using NRSER::Types
23
23
 
24
24
 
@@ -29,7 +29,7 @@ using NRSER::Types
29
29
  #
30
30
  module Locd::Newsyslog
31
31
 
32
- include NRSER::Logging::Mixin
32
+ include NRSER::Log::Mixin
33
33
 
34
34
 
35
35
  # Default place to work out of.
@@ -1,10 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Refinements
4
- # =======================================================================
5
-
6
- using NRSER
7
-
8
3
 
9
4
  # Definitions
10
5
  # =======================================================================
@@ -1,11 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  # encoding: UTF-8
3
3
 
4
- # Refinements
5
- # =======================================================================
6
-
7
- using NRSER
8
-
9
4
 
10
5
  # Definitions
11
6
  # =======================================================================
@@ -43,7 +38,7 @@ module Locd::Proxy
43
38
  # ============================================================================
44
39
 
45
40
  # Add {.logger} and {#logger} methods
46
- include NRSER::Logging::Mixin
41
+ include NRSER::Log::Mixin
47
42
 
48
43
 
49
44
  # Module Methods
@@ -1,23 +1,5 @@
1
1
  # frozen_string_literal: true
2
-
3
- # Requirements
4
- # =======================================================================
5
-
6
- # Stdlib
7
- # -----------------------------------------------------------------------
8
-
9
- # Deps
10
- # -----------------------------------------------------------------------
11
-
12
- # Project / Package
13
- # -----------------------------------------------------------------------
14
-
15
-
16
- # Refinements
17
- # =======================================================================
18
-
19
- using NRSER
20
-
2
+ # encoding: UTF-8
21
3
 
22
4
  # Definitions
23
5
  # =======================================================================
@@ -47,7 +47,7 @@ Gem::Specification.new do |spec|
47
47
  # ----------------------------------------------------------------------------
48
48
 
49
49
  # My guns
50
- spec.add_dependency "nrser", '~> 0.2.1'
50
+ spec.add_dependency "nrser", '~> 0.3.1'
51
51
 
52
52
  # Used to process command templates from projects' `//dev/locd.yml` files
53
53
  spec.add_dependency "cmds", ">= 0.2.10"
@@ -59,7 +59,7 @@ Gem::Specification.new do |spec|
59
59
  spec.add_dependency 'plist', '~> 3.4'
60
60
 
61
61
  # Atli, my fork of Thor for CLI interface
62
- spec.add_dependency 'atli', '>= 0.1.5'
62
+ spec.add_dependency 'atli', '~> 0.1.6'
63
63
 
64
64
  #
65
65
  # spec.add_dependency 'terminal-table', '~> 1.8'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - nrser
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-22 00:00:00.000000000 Z
11
+ date: 2018-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: 0.2.1
117
+ version: 0.3.1
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: 0.2.1
124
+ version: 0.3.1
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: cmds
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -168,16 +168,16 @@ dependencies:
168
168
  name: atli
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
- - - ">="
171
+ - - "~>"
172
172
  - !ruby/object:Gem::Version
173
- version: 0.1.5
173
+ version: 0.1.6
174
174
  type: :runtime
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
- - - ">="
178
+ - - "~>"
179
179
  - !ruby/object:Gem::Version
180
- version: 0.1.5
180
+ version: 0.1.6
181
181
  description:
182
182
  email:
183
183
  - neil@ztkae.com
@@ -217,6 +217,7 @@ files:
217
217
  - lib/locd/cli/command/base.rb
218
218
  - lib/locd/cli/command/job.rb
219
219
  - lib/locd/cli/command/main.rb
220
+ - lib/locd/cli/command/project.rb
220
221
  - lib/locd/cli/command/proxy.rb
221
222
  - lib/locd/cli/command/rotate_logs.rb
222
223
  - lib/locd/cli/command/site.rb