lctl 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in lctl.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,17 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ lctl (0.0.1)
5
+ thor
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ thor (0.14.6)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ lctl!
17
+ thor
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # lctl
2
+
3
+ lctl is short for launchctl. This is just something I hacked together to avoid
4
+ having to type long paths when restarting postgresql and similar, which I
5
+ installed using Homebrew.
6
+
7
+ ## Author
8
+
9
+ James Conroy-Finn
10
+
11
+ ## Installation
12
+
13
+ gem install lctl
14
+
15
+ ## Usage
16
+
17
+ You can search for plists in ~/Libary/LaunchAgents and ~/Library/LaunchDaemons
18
+ using `lctl list [NAME]`. With no name all plists will be output. With a name
19
+ only files that contain the name will be output.
20
+
21
+ The same search mechanism is used when loading and unloading plists. If more
22
+ than one match is found the list of matches will be output and a warning
23
+ printed.
24
+
25
+ lctl help [TASK] # Describe available tasks or one specific task
26
+ lctl list [NAME] # Find any agents or daemons matching optional NAME
27
+ lctl load NAME # Load a launchd process in ~/Library/Launch[Agents|Daemons]
28
+ lctl unload NAME # Unload a launchd process in ~/Library/Launch[Agents|Daemons]
29
+ lctl version # Prints Lctl's version information
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/bin/lctl ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'lctl'
5
+ rescue LoadError
6
+ require File.expand_path('../../lib/lctl', __FILE__)
7
+ end
8
+
9
+ Lctl::CLI.start
data/lctl.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "lctl/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "lctl"
7
+ s.version = Lctl::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["James Conroy-Finn"]
10
+ s.email = ["james@logi.cl"]
11
+ s.homepage = "http://github.com/jcf/lctl"
12
+ s.summary = %q{Find, load and unload launchd agents and daemons}
13
+ s.description = %q{Find, load and unload launchd agents and daemons in your home folder}
14
+
15
+ s.rubyforge_project = "lctl"
16
+
17
+ s.add_dependency 'thor'
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.require_paths = ["lib"]
23
+ end
data/lib/lctl/cli.rb ADDED
@@ -0,0 +1,55 @@
1
+ require 'thor'
2
+
3
+ class Lctl::CLI < Thor
4
+ default_task :start
5
+
6
+ desc 'load NAME', 'Load a launchd process in ~/Library/Launch[Agents|Daemons]'
7
+ def load(name)
8
+ find(name, :load)
9
+ end
10
+
11
+ desc 'unload NAME', 'Unload a launchd process in ~/Library/Launch[Agents|Daemons]'
12
+ def unload(name)
13
+ find(name, :unload)
14
+ end
15
+
16
+ desc 'list [NAME]', 'Find any agents or daemons matching optional NAME'
17
+ def list(name = nil)
18
+ find(name, :list)
19
+ end
20
+
21
+ desc 'version', "Prints Lctl's version information"
22
+ def version
23
+ say "Lctl version #{Lctl::VERSION}"
24
+ end
25
+ map %w(-v --version) => :version
26
+
27
+ private
28
+
29
+ def find(name, action)
30
+ files = ::Lctl::Finder.new(name.to_s).files
31
+
32
+ return list_files(files) if action == :list
33
+
34
+ if files.length == 1
35
+ say("#{action.capitalize}ing #{files.first}")
36
+ %x(launchctl #{action} #{files.first})
37
+ else
38
+ say "Expected to find one file. Found #{files.length} files", :red
39
+ print_files(files, :red)
40
+ end
41
+ end
42
+
43
+ def list_files(files)
44
+ if files.empty?
45
+ say "Couldn't find any files matching \"#{name}\"", :red
46
+ else
47
+ say "Found #{files.length} file(s)", :green
48
+ print_files(files)
49
+ end
50
+ end
51
+
52
+ def print_files(files, color = :green)
53
+ files.each { |file| say " - #{file}" }
54
+ end
55
+ end
@@ -0,0 +1,21 @@
1
+ class Lctl::Finder
2
+ def initialize(name)
3
+ @name = name
4
+ end
5
+
6
+ def files
7
+ @files ||= Dir.glob(glob, File::FNM_CASEFOLD)
8
+ end
9
+
10
+ private
11
+
12
+ def name
13
+ @name.to_s.gsub(/(\.plist)?$/, '')
14
+ end
15
+
16
+ def glob
17
+ File.expand_path(
18
+ "~/Library/Launch{Agents,Daemons}/*#{name}*.plist"
19
+ )
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module Lctl
2
+ VERSION = "0.0.1"
3
+ end
data/lib/lctl.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/setup'
2
+
3
+ module Lctl
4
+ end
5
+
6
+ $:.push File.expand_path("../lib", __FILE__)
7
+
8
+ require 'lctl/version'
9
+ require 'lctl/finder'
10
+ require 'lctl/cli'
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lctl
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - James Conroy-Finn
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-02-03 00:00:00 +00:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: thor
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ description: Find, load and unload launchd agents and daemons in your home folder
34
+ email:
35
+ - james@logi.cl
36
+ executables:
37
+ - lctl
38
+ extensions: []
39
+
40
+ extra_rdoc_files: []
41
+
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - Gemfile.lock
46
+ - README.md
47
+ - Rakefile
48
+ - bin/lctl
49
+ - lctl.gemspec
50
+ - lib/lctl.rb
51
+ - lib/lctl/cli.rb
52
+ - lib/lctl/finder.rb
53
+ - lib/lctl/version.rb
54
+ has_rdoc: true
55
+ homepage: http://github.com/jcf/lctl
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options: []
60
+
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ segments:
69
+ - 0
70
+ version: "0"
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ requirements: []
80
+
81
+ rubyforge_project: lctl
82
+ rubygems_version: 1.3.7
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Find, load and unload launchd agents and daemons
86
+ test_files: []
87
+