vim_printer 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +5 -1
- data/lib/vim_printer/cli.rb +60 -3
- data/lib/vim_printer/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: 5db6c8f84609703178fb48f9917034197fe3a0f3
|
4
|
+
data.tar.gz: 7e764609c4a0860849ac65cfb9e57e2195886439
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee03cbf46d41b1e06a9d3d0c92532471f663de84fd06c038f72872e64c75d84a2078d0305a349c466895a486c065ae842d621f54a7c344b3f9a3d74f46fb3556
|
7
|
+
data.tar.gz: 38485f6aec3fd9f5340804b71fcb9d370c258bc4ab6d07d6dd7adeb015abde08319912042f59a0d1b9d8ad29c9db6e9f13c810cbe53bc7efc6afca38ea200c73
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -155,7 +155,11 @@ Options:
|
|
155
155
|
# Default: 'default'
|
156
156
|
-c, [--index], [--no-index] # Generate the index.html file for the result (optional)
|
157
157
|
# Default: --index
|
158
|
-
|
158
|
+
-s, [--shell-command] # Use the input file list from the result of the given shell command (optional)
|
159
|
+
# Note: the command must be result in the list of files
|
160
|
+
# This option ignore any of the following options -e, -f, -n, -x, -i if specified
|
161
|
+
# e.g. --shell-command 'git diff --name-only HEAD~2 | grep -v test'
|
162
|
+
# e.g. --shell-command 'find . -type f -iname "*.rb" | grep -v test'
|
159
163
|
Print files to (x)html using Vim
|
160
164
|
```
|
161
165
|
|
data/lib/vim_printer/cli.rb
CHANGED
@@ -26,6 +26,10 @@ module VimPrinter
|
|
26
26
|
desc: "Generate the index.html file for the result",
|
27
27
|
type: :boolean,
|
28
28
|
default: true
|
29
|
+
method_option :shell_command,
|
30
|
+
aliases: "-s",
|
31
|
+
desc: "Use input file list from the result of the given shell command",
|
32
|
+
type: :string
|
29
33
|
def print
|
30
34
|
opts = options.symbolize_keys
|
31
35
|
if opts[:version]
|
@@ -63,7 +67,11 @@ Options:
|
|
63
67
|
# Default: 'default'
|
64
68
|
-c, [--index], [--no-index] # Generate the index.html file for the result (optional)
|
65
69
|
# Default: --index
|
66
|
-
|
70
|
+
-s, [--shell-command] # Use the input file list from the result of the given shell command (optional)
|
71
|
+
# Note: the command must be result in the list of files
|
72
|
+
# This option ignore any of the following options -e, -f, -n, -x, -i if specified
|
73
|
+
# e.g. --shell-command 'git diff --name-only HEAD~2 | grep -v test'
|
74
|
+
# e.g. --shell-command 'find . -type f -iname "*.rb" | grep -v test | grep -v _spec'
|
67
75
|
Print files to (x)html using Vim
|
68
76
|
EOS
|
69
77
|
end
|
@@ -73,12 +81,61 @@ Print files to (x)html using Vim
|
|
73
81
|
|
74
82
|
private
|
75
83
|
|
84
|
+
# Get the appropriate input from the options
|
85
|
+
#
|
86
|
+
# @param [Hash<Symbol, Object>] args the input options
|
87
|
+
# @option args [String] :shell_input the shell input string if any
|
88
|
+
# @return [Array<String>] list of files in the format
|
89
|
+
#
|
90
|
+
# ["./Gemfile", "./lib/vim_printer/cli.rb", ..]
|
91
|
+
def get_input_files(args = {})
|
92
|
+
shell_command = args.fetch(:shell_command, nil)
|
93
|
+
if shell_command.nil?
|
94
|
+
# use other options if we don't use the '--shell-input' option
|
95
|
+
CodeLister.files(args)
|
96
|
+
else
|
97
|
+
files_from_shell_command(shell_command, args[:base_dir])
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# Execute the command in the shell and return the output list for use
|
102
|
+
# e.g. `git diff --name-only HEAD~1` is getting the list of files that have been
|
103
|
+
# updated in the last commit
|
104
|
+
#
|
105
|
+
# @param [String] shell_input the input command to be executed in the shell
|
106
|
+
# @param [String] base_dir the starting directory
|
107
|
+
# @return [Array<String>] file list or empty list if the shell command is not valid
|
108
|
+
def files_from_shell_command(command, base_dir)
|
109
|
+
files = AgileUtils::Helper.shell(command.split(" ")).split(/\n/)
|
110
|
+
# Adapt the result and make sure that it start with "./"
|
111
|
+
# like the result from 'CodeLister.files()' method
|
112
|
+
files.map! do |file|
|
113
|
+
if file =~ /^\.\//
|
114
|
+
# skip if the file start with './' string
|
115
|
+
file
|
116
|
+
else
|
117
|
+
# add './' to the one that does not already have one
|
118
|
+
"./#{file}"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
# Note: this make sure that it work with deleted file when use
|
122
|
+
# this with 'git diff --name-only HEAD~2'
|
123
|
+
files.delete_if { |file| !File.exist?(file.gsub(/^\./, base_dir)) }
|
124
|
+
rescue RuntimeError => e
|
125
|
+
# just return the empty list, if the user specified invalid command for 'shell_input' option
|
126
|
+
return []
|
127
|
+
end
|
128
|
+
|
76
129
|
# Main entry point to export the code
|
77
130
|
#
|
78
131
|
# @param [Hash<Symbol, Object>] options the options argument
|
79
132
|
def execute(options = {})
|
80
|
-
input_files =
|
81
|
-
|
133
|
+
input_files = get_input_files(options)
|
134
|
+
# we want to avoid printing the binary file
|
135
|
+
input_files.delete_if do |file|
|
136
|
+
File.binary?(file.gsub(/^\./, options[:base_dir]))
|
137
|
+
end
|
138
|
+
|
82
139
|
if input_files.empty?
|
83
140
|
puts "No file found for your option: #{options}"
|
84
141
|
return
|
data/lib/vim_printer/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vim_printer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Burin Choomnuan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|