command-genie 0.0.2 → 0.1.0

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/genie +30 -12
  3. data/lib/genie.rb +1 -0
  4. data/lib/genie/version.rb +1 -1
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 14f9cdaa9434a2f4b931d25c5587e2f31127ef0a
4
- data.tar.gz: 93709c2826bc446bf3d13e1982d958b584e4d563
3
+ metadata.gz: e85595987a1e849138f28c3420bf1457a6effdba
4
+ data.tar.gz: 950bcc6ef3f4baf8717257c7ecd96d4e08e40717
5
5
  SHA512:
6
- metadata.gz: d0c7078ca4894af8e6ae70fefaa0e106931444a7e1680cc993490eebbf0db017d7c34ff3a740c5d008369f855c54c0d9732c9bc43e510cf67895c241cb90a7e0
7
- data.tar.gz: 545b6a86669ad5148e3c806e3b6186a169634c663a287fc081d9893d12df07d356200ac14e3c0f93eafcc7710c5a46c6cbc5fa4dc954f05afb20b166e4a1cbf5
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, '0.0.2'
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
- File.open(cmd_config_path) do |f|
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
@@ -1 +1,2 @@
1
1
  require 'genie/genie'
2
+ require 'genie/version'
data/lib/genie/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CommandGenie
2
- VERSION = '0.0.2'
2
+ VERSION = '0.1.0'
3
3
  end
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.2
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-09 00:00:00.000000000 Z
11
+ date: 2016-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander