command-genie 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/genie +30 -12
- data/lib/genie.rb +1 -0
- data/lib/genie/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e85595987a1e849138f28c3420bf1457a6effdba
|
4
|
+
data.tar.gz: 950bcc6ef3f4baf8717257c7ecd96d4e08e40717
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe602357a7eafc15fc7c23098d5bc157c543ed645602f57c7910bb258464b3425ee0a19201d9636f01e8f3f6ba5b1b7b4cdc1b5a0af8532e36ce0c9ccec7d5e7
|
7
|
+
data.tar.gz: bb515303a32e51081c2b914d3e2f6038f93f2dbccf3cb6a1bcaf4f10f6bea0841cee78da74598ee1e2f70ff4e7d5a4d86e47211e67ae7b0d6e1308bd3fbf3c63
|
data/bin/genie
CHANGED
@@ -4,6 +4,7 @@ require 'rubygems'
|
|
4
4
|
require 'commander/import'
|
5
5
|
require 'fileutils'
|
6
6
|
require 'psych'
|
7
|
+
require 'genie'
|
7
8
|
|
8
9
|
APP_NAME = 'genie'
|
9
10
|
HELP_STRING = "Create commands bound to directories. E.g. create a `push` command
|
@@ -63,7 +64,7 @@ directory.
|
|
63
64
|
"
|
64
65
|
TICK_CHAR = "\u2713"
|
65
66
|
|
66
|
-
program :version,
|
67
|
+
program :version, CommandGenie::VERSION
|
67
68
|
program :description, HELP_STRING
|
68
69
|
|
69
70
|
script_name = File.basename($PROGRAM_NAME)
|
@@ -86,21 +87,11 @@ if script_name != APP_NAME
|
|
86
87
|
c.description = "Run a command from #{cmd_config_path} that matches the current directory"
|
87
88
|
c.example 'Run command', "$ #{script_name}"
|
88
89
|
c.action do |args, options|
|
89
|
-
#Careful, say doesn't return true-ish
|
90
|
-
if (script_name == APP_NAME && (args.nil? || args.empty?))
|
91
|
-
say HELP_STRING
|
92
|
-
abort
|
93
|
-
end
|
94
90
|
say_error "Specify the name of the new command you want to create:
|
95
91
|
|
96
92
|
#{APP_NAME} create <command>
|
97
93
|
" and abort if script_name == APP_NAME
|
98
|
-
|
99
|
-
mapping = Psych.load(f.read)
|
100
|
-
mapping = Hash[mapping.map{|k,v|[k.chomp('/'), v]}]
|
101
|
-
dir = Dir.pwd
|
102
|
-
found = dir_matching(mapping.keys, dir)
|
103
|
-
cmd = mapping[found]
|
94
|
+
with_command(script_name) do |cmd|
|
104
95
|
if cmd && !cmd.empty?
|
105
96
|
say "Running: #{cmd}"
|
106
97
|
`#{cmd}`
|
@@ -110,6 +101,21 @@ if script_name != APP_NAME
|
|
110
101
|
end
|
111
102
|
end
|
112
103
|
end
|
104
|
+
command :show do |c|
|
105
|
+
c.syntax = "#{script_name}"
|
106
|
+
c.summary = "Show the command to run, from #{cmd_config_path} that matches the current directory"
|
107
|
+
c.description = c.summary
|
108
|
+
c.example 'Show command', "$ #{script_name}"
|
109
|
+
c.action do |args, options|
|
110
|
+
with_command(script_name) do |cmd|
|
111
|
+
if cmd && !cmd.empty?
|
112
|
+
say "#{cmd}"
|
113
|
+
else
|
114
|
+
say_error "No matching command found for `#{dir}`."
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
113
119
|
end
|
114
120
|
|
115
121
|
if script_name == APP_NAME
|
@@ -170,3 +176,15 @@ def create_command(new_cmd)
|
|
170
176
|
say "#{TICK_CHAR} New command (softlink) `#{new_cmd}` created by genie."
|
171
177
|
say "TODO: You should move `#{new_cmd}` to a directory included in your $PATH so you can use it anywhere."
|
172
178
|
end
|
179
|
+
|
180
|
+
def with_command(script_name, &block)
|
181
|
+
cmd_config_path = config_path(script_name)
|
182
|
+
File.open(cmd_config_path) do |f|
|
183
|
+
mapping = Psych.load(f.read)
|
184
|
+
mapping = Hash[mapping.map{|k,v|[k.chomp('/'), v]}]
|
185
|
+
dir = Dir.pwd
|
186
|
+
found = dir_matching(mapping.keys, dir)
|
187
|
+
cmd = mapping[found]
|
188
|
+
block.call(cmd)
|
189
|
+
end
|
190
|
+
end
|
data/lib/genie.rb
CHANGED
data/lib/genie/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: command-genie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hwee-Boon Yar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: commander
|