lunchy 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/History.md +8 -1
  2. data/README.md +2 -1
  3. data/bin/lunchy +3 -1
  4. data/lib/lunchy.rb +26 -4
  5. metadata +2 -13
data/History.md CHANGED
@@ -1,6 +1,13 @@
1
1
  Changes
2
2
  ================
3
3
 
4
+ 0.5.0
5
+ ----
6
+
7
+ - Add default output to start and stop (joncooper)
8
+ - Add 'edit' command to edit the matching plist file (AndreyChernyh)
9
+ - Allow management of daemons in /System/Library/LaunchDaemons when lunchy is run as root (fhemberger)
10
+
4
11
  0.4.0
5
12
  -----
6
13
 
@@ -24,4 +31,4 @@ Changes
24
31
  0.1.0
25
32
  -----
26
33
 
27
- - Initial release
34
+ - Initial release
data/README.md CHANGED
@@ -12,6 +12,7 @@ Lunchy aims to be that friendly tool by wrapping launchctl and providing a few s
12
12
  - stop [pattern]
13
13
  - restart [pattern]
14
14
  - status [pattern]
15
+ - install [file]
15
16
 
16
17
  where pattern is just a substring that matches the agent's plist filename. If you don't use a unique pattern, Lunchy will warn you of this and give you a list of the matching items instead.
17
18
 
@@ -54,4 +55,4 @@ Lunchy was written as part of my project time at [Carbon Five](http://carbonfive
54
55
  About
55
56
  -----------------
56
57
 
57
- Mike Perham, [@mperham](http://twitter.com/mperham), [mikeperham.com](http://mikeperham.com/)
58
+ Mike Perham, [@mperham](http://twitter.com/mperham), [mikeperham.com](http://mikeperham.com/)
data/bin/lunchy CHANGED
@@ -5,7 +5,7 @@ require 'optparse'
5
5
  require 'lunchy'
6
6
 
7
7
  CONFIG = { :verbose => false, :write => false }
8
- OPERATIONS = %w(start stop restart ls list status install)
8
+ OPERATIONS = %w(start stop restart ls list status install edit)
9
9
 
10
10
  option_parser = OptionParser.new do |opts|
11
11
  opts.banner = "Lunchy #{Lunchy::VERSION}, the friendly launchctl wrapper\nUsage: #{__FILE__} [#{OPERATIONS.join('|')}] [options]"
@@ -29,6 +29,7 @@ Supported commands:
29
29
  restart [pattern] Stop and start the first agent matching [pattern]
30
30
  status [pattern] Show the PID and label for all agents, with optional [pattern] filter
31
31
  install [file] Installs [file] to ~/Library/LaunchAgents or /Library/LaunchAgents (whichever it finds first)
32
+ edit [pattern] Opens the launchctl daemon file in the default editor (EDITOR environment variable)
32
33
 
33
34
  -w will persist the start/stop command so the agent will load on startup or never load, respectively.
34
35
 
@@ -38,6 +39,7 @@ Example:
38
39
  lunchy stop mongo
39
40
  lunchy status mysql
40
41
  lunchy install /usr/local/Cellar/redis/2.2.2/io.redis.redis-server.plist
42
+ lunchy edit mongo
41
43
 
42
44
  Note: if you run lunchy as root, you can manage daemons in /Library/LaunchDaemons also.
43
45
  EOS
data/lib/lunchy.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'fileutils'
2
2
 
3
3
  class Lunchy
4
- VERSION = '0.4.0'
4
+ VERSION = '0.5.0'
5
5
 
6
6
  def start(params)
7
7
  raise ArgumentError, "start [-w] [name]" if params.empty?
@@ -14,6 +14,7 @@ class Lunchy
14
14
  return puts "No daemon found matching '#{name}'" if !name
15
15
  else
16
16
  execute("launchctl load #{CONFIG[:write] ? '-w ' : ''}#{files.values.first.inspect}")
17
+ puts "started #{files.keys.first}"
17
18
  end
18
19
  end
19
20
 
@@ -28,6 +29,7 @@ class Lunchy
28
29
  return puts "No daemon found matching '#{name}'" if !name
29
30
  else
30
31
  execute("launchctl unload #{CONFIG[:write] ? '-w ' : ''}#{files.values.first.inspect}")
32
+ puts "stopped #{files.keys.first}"
31
33
  end
32
34
  end
33
35
 
@@ -65,11 +67,31 @@ class Lunchy
65
67
  end
66
68
  end
67
69
 
70
+ def edit(params)
71
+ raise ArgumentError, "edit [name]" if params.empty?
72
+ name = params[0]
73
+ files = plists.select {|k,v| k =~ /#{name}/i }
74
+ files = Hash[files] if files.is_a?(Array) # ruby 1.8
75
+ if files.size > 1
76
+ return puts "Multiple daemons found matching '#{name}'. You need to be more specific. Matches found are:\n" + files.keys.join("\n")
77
+ elsif files.size == 0
78
+ return puts "No daemon found matching '#{name}'" if !name
79
+ else
80
+ editor = ENV['EDITOR']
81
+ if editor.nil?
82
+ raise 'EDITOR environment variable is not set'
83
+ else
84
+ execute("#{editor} #{files.values.first.inspect} > `tty`")
85
+ end
86
+ end
87
+ end
88
+
68
89
  private
69
90
 
70
91
  def execute(cmd)
71
92
  puts "Executing: #{cmd}" if verbose?
72
- puts `#{cmd}`
93
+ emitted = `#{cmd}`
94
+ puts emitted unless emitted.empty?
73
95
  end
74
96
 
75
97
  def plists
@@ -86,7 +108,7 @@ class Lunchy
86
108
 
87
109
  def dirs
88
110
  result = %w(/Library/LaunchAgents ~/Library/LaunchAgents)
89
- result << '/Library/LaunchDaemons' if root?
111
+ result.push('/Library/LaunchDaemons', '/System/Library/LaunchDaemons') if root?
90
112
  result
91
113
  end
92
114
 
@@ -111,4 +133,4 @@ class Lunchy
111
133
  def verbose?
112
134
  CONFIG[:verbose]
113
135
  end
114
- end
136
+ end
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lunchy
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
5
4
  prerelease:
6
- segments:
7
- - 0
8
- - 4
9
- - 0
10
- version: 0.4.0
5
+ version: 0.5.0
11
6
  platform: ruby
12
7
  authors:
13
8
  - Mike Perham
@@ -15,7 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-05-13 00:00:00 -07:00
13
+ date: 2011-08-05 00:00:00 -07:00
19
14
  default_executable:
20
15
  dependencies: []
21
16
 
@@ -49,18 +44,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
49
44
  requirements:
50
45
  - - ">="
51
46
  - !ruby/object:Gem::Version
52
- hash: 3
53
- segments:
54
- - 0
55
47
  version: "0"
56
48
  required_rubygems_version: !ruby/object:Gem::Requirement
57
49
  none: false
58
50
  requirements:
59
51
  - - ">="
60
52
  - !ruby/object:Gem::Version
61
- hash: 3
62
- segments:
63
- - 0
64
53
  version: "0"
65
54
  requirements: []
66
55