macdiff 0.0.3
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.
- checksums.yaml +7 -0
- data/.github/workflows/main.yml +18 -0
- data/.gitignore +46 -0
- data/.rspec +3 -0
- data/.rubocop.yml +45 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +19 -0
- data/Guardfile +23 -0
- data/LICENSE.txt +21 -0
- data/README.md +69 -0
- data/Rakefile +33 -0
- data/b/a1.txt +0 -0
- data/b/b1.txt +0 -0
- data/b/c/e.txt +0 -0
- data/b/c1.txt +1 -0
- data/b/x/e.txt +0 -0
- data/b/x/g.txt +1 -0
- data/b/x/h.txt +0 -0
- data/bin/console +16 -0
- data/bin/k +36 -0
- data/bin/kgitsync +76 -0
- data/bin/khotfix +244 -0
- data/bin/setup +11 -0
- data/exe/macdiff +18 -0
- data/ext/macdiff/extconf.rb +5 -0
- data/ext/macdiff/macdiff.c +9 -0
- data/ext/macdiff/macdiff.h +6 -0
- data/hooks/pre-commit +87 -0
- data/hooks/update-version +21 -0
- data/lib/macdiff/app.rb +24 -0
- data/lib/macdiff/cli.rb +21 -0
- data/lib/macdiff/command.rb +243 -0
- data/lib/macdiff/commands/.keep +1 -0
- data/lib/macdiff/diff_folder.rb +66 -0
- data/lib/macdiff/templates/.keep +1 -0
- data/lib/macdiff/version.rb +5 -0
- data/lib/macdiff.rb +9 -0
- data/macdiff.gemspec +60 -0
- metadata +129 -0
data/bin/khotfix
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
#NOTE: you may need change file permissions
|
|
4
|
+
# chmod +x bin/khotfix
|
|
5
|
+
|
|
6
|
+
# Create a Versioned HotFix in Git and update the VERSION #
|
|
7
|
+
# USAGE
|
|
8
|
+
#
|
|
9
|
+
# ./bin/khotfix.sh 'my brand new hot fix'
|
|
10
|
+
|
|
11
|
+
# HELPERS
|
|
12
|
+
clear
|
|
13
|
+
|
|
14
|
+
l_heading ()
|
|
15
|
+
{
|
|
16
|
+
heading=$1
|
|
17
|
+
|
|
18
|
+
echo "======================================================================"
|
|
19
|
+
echo "${heading}"
|
|
20
|
+
echo "======================================================================"
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
l_line ()
|
|
24
|
+
{
|
|
25
|
+
echo "----------------------------------------------------------------------"
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
l_title ()
|
|
29
|
+
{
|
|
30
|
+
title=$1
|
|
31
|
+
|
|
32
|
+
l_line
|
|
33
|
+
echo "${title}"
|
|
34
|
+
l_line
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
l ()
|
|
38
|
+
{
|
|
39
|
+
title=$1
|
|
40
|
+
|
|
41
|
+
echo "${title}"
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
lkv ()
|
|
45
|
+
{
|
|
46
|
+
title=$1
|
|
47
|
+
value=$2
|
|
48
|
+
|
|
49
|
+
printf "%-25s : %s\n" "$title" "$value"
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
# expect 1 argument
|
|
54
|
+
MESSAGE=$1
|
|
55
|
+
|
|
56
|
+
l_heading "Make Hotfix - '${MESSAGE}'"
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
# This environment var will prevent git from asking for merge messages
|
|
60
|
+
export GIT_MERGE_AUTOEDIT=no
|
|
61
|
+
|
|
62
|
+
# Set up colour support, if we have it
|
|
63
|
+
# Are stdout and stderr both connected to a terminal, If not then don't set colours
|
|
64
|
+
if [ -t 1 -a -t 2 ]
|
|
65
|
+
then
|
|
66
|
+
if tput -V >/dev/null 2>&1
|
|
67
|
+
then
|
|
68
|
+
C_RED=`tput setaf 1`
|
|
69
|
+
C_GREEN=`tput setaf 2`
|
|
70
|
+
C_BROWN=`tput setaf 3`
|
|
71
|
+
C_BLUE=`tput setaf 4`
|
|
72
|
+
C_RESET=`tput sgr0`
|
|
73
|
+
fi
|
|
74
|
+
fi
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
exit_error ()
|
|
78
|
+
{
|
|
79
|
+
# dont display if string is zero length
|
|
80
|
+
[ -z "$1" ] || echo "${C_RED}Error: ${C_BROWN} $1 ${C_RESET}"
|
|
81
|
+
exit 1
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
# check arguments
|
|
86
|
+
[ ! -z "${MESSAGE}" ] || exit_error "You must pass a message when making a hotfix"
|
|
87
|
+
|
|
88
|
+
# make sure we are in a git tree
|
|
89
|
+
[ "`git rev-parse --is-inside-work-tree`" = "true" ] || exit_error "NOT a git repository"
|
|
90
|
+
l "Repository check OK"
|
|
91
|
+
|
|
92
|
+
CURRENT_BRANCH=`git branch | awk '/^\*/{print $2}'`
|
|
93
|
+
|
|
94
|
+
lkv "CURRENT_BRANCH" "${CURRENT_BRANCH}"
|
|
95
|
+
|
|
96
|
+
# check that we are on develop or master
|
|
97
|
+
[ "${CURRENT_BRANCH}" = "master" -o "${CURRENT_BRANCH}" = "develop" ] || exit_error "You MUST be on either the master or development branch"
|
|
98
|
+
l "OK: Branch"
|
|
99
|
+
|
|
100
|
+
# check that the current branch is NOT clean (we need changes to make a hotfix)
|
|
101
|
+
[ ! -z "`git status --porcelain`" ] || exit_error "Working copy is clean - no hotfix"
|
|
102
|
+
l "OK: Working copy has hotfix ready"
|
|
103
|
+
|
|
104
|
+
# fetch from origin
|
|
105
|
+
git fetch origin || exit_error "Failed to fetch from origin"
|
|
106
|
+
l "OK: Fsetch from origin"
|
|
107
|
+
|
|
108
|
+
# get the current directory that this script is in.
|
|
109
|
+
# we assume that the other scripts are in the same directory
|
|
110
|
+
SYNC_SCRIPT=kgitsync
|
|
111
|
+
SCRIPT_DIR=`dirname $0`
|
|
112
|
+
|
|
113
|
+
# ----------------------------------------------------------------------
|
|
114
|
+
# GET VERSION NUMBER
|
|
115
|
+
# ----------------------------------------------------------------------
|
|
116
|
+
|
|
117
|
+
l_title 'GET VERSION NUMBER'
|
|
118
|
+
|
|
119
|
+
# Get the last tag version
|
|
120
|
+
VERSION=`git tag | sort -V | tail -1`
|
|
121
|
+
lkv "CURENT VERSION" "${VERSION}"
|
|
122
|
+
|
|
123
|
+
# NOTE, if you don't have a TAG then you might need to manually do
|
|
124
|
+
# git flow hotfix start v0.01.001
|
|
125
|
+
# git flow hotfix finish v0.01.001
|
|
126
|
+
|
|
127
|
+
# Verify its format
|
|
128
|
+
[[ "`git tag | sort -V | tail -1`" =~ ^v[0-9]{1,2}.[0-9]{1,2}.[0-9]{1,3}$ ]] || exit_error "Bad version format, version=${VERSION}"
|
|
129
|
+
# extract the version components
|
|
130
|
+
IFS=. read MAJOR_VERSION MINOR_VERSION PATCH_VERSION <<< "${VERSION}"
|
|
131
|
+
|
|
132
|
+
# inc the patch version. note: force base 10 as leading 0 makes bash think this is octal
|
|
133
|
+
PATCH_VERSION=$((10#${PATCH_VERSION} + 1))
|
|
134
|
+
lkv 'Patch #' "${PATCH_VERSION}"
|
|
135
|
+
|
|
136
|
+
# assemble the new version
|
|
137
|
+
NEW_VERSION="${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}"
|
|
138
|
+
lkv "NEW VERSION" "${NEW_VERSION}"
|
|
139
|
+
|
|
140
|
+
./hooks/update-version "${NEW_VERSION}" || exit_error "could not update version.rb you may need to run [chmod +x hooks/update-version]"
|
|
141
|
+
|
|
142
|
+
l_line
|
|
143
|
+
l 'git add .'
|
|
144
|
+
git add .
|
|
145
|
+
|
|
146
|
+
l 'git status'
|
|
147
|
+
l_line
|
|
148
|
+
git status
|
|
149
|
+
|
|
150
|
+
# ----------------------------------------------------------------------
|
|
151
|
+
# Before doing anything, add the files and then run the commit hook
|
|
152
|
+
# Then stash any changes - working directory will be clean after this
|
|
153
|
+
# The commit hook is where we can check for any debugging code that has
|
|
154
|
+
# gone into the code and abort the commit
|
|
155
|
+
# ----------------------------------------------------------------------
|
|
156
|
+
|
|
157
|
+
l 'check for debugging code'
|
|
158
|
+
./hooks/pre-commit || exit_error "remove debugging code from the commit - then run again"
|
|
159
|
+
|
|
160
|
+
l "Stash changes to [git_make_hotfix: ${MESSAGE}]"
|
|
161
|
+
|
|
162
|
+
git stash save "git_make_hotfix: ${MESSAGE}"
|
|
163
|
+
|
|
164
|
+
l "OK: Stashed"
|
|
165
|
+
|
|
166
|
+
l_title 'Master/Develop Branches'
|
|
167
|
+
# ----------------------------------------------------------------------
|
|
168
|
+
# update develop
|
|
169
|
+
# ----------------------------------------------------------------------
|
|
170
|
+
|
|
171
|
+
lkv "Develop" "Synchronized"
|
|
172
|
+
git checkout develop || exit_error "Failed to checkout develop branch"
|
|
173
|
+
lkv "Develop" "Switched"
|
|
174
|
+
git merge origin/develop || exit_error "Failed to merge develop from origin"
|
|
175
|
+
lkv "Develop" "Merged and upto date"
|
|
176
|
+
|
|
177
|
+
# ----------------------------------------------------------------------
|
|
178
|
+
# update master
|
|
179
|
+
# ----------------------------------------------------------------------
|
|
180
|
+
|
|
181
|
+
lkv "Master" "Synchronized"
|
|
182
|
+
git checkout master || exit_error "Failed to checkout master branch"
|
|
183
|
+
lkv "Master" "Switched"
|
|
184
|
+
git merge origin/master || exit_error "Failed to merge master from origin"
|
|
185
|
+
lkv "Master" "Merged and upto date"
|
|
186
|
+
|
|
187
|
+
# ----------------------------------------------------------------------
|
|
188
|
+
# start the hotfix
|
|
189
|
+
# ----------------------------------------------------------------------
|
|
190
|
+
|
|
191
|
+
l_title 'Hotfix'
|
|
192
|
+
|
|
193
|
+
lkv "Version" "${NEW_VERSION}"
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
lkv "git flow hotfix start" "${NEW_VERSION}"
|
|
198
|
+
|
|
199
|
+
git flow hotfix start "${NEW_VERSION}" || exit_error "Failed to start hotfix ${NEW_VERSION}"
|
|
200
|
+
|
|
201
|
+
HOTFIX_BRANCH="hotfix/${NEW_VERSION}"
|
|
202
|
+
|
|
203
|
+
lkv "started" "${HOTFIX_BRANCH}"
|
|
204
|
+
|
|
205
|
+
# ----------------------------------------------------------------------
|
|
206
|
+
# commit the stashed changes
|
|
207
|
+
# ----------------------------------------------------------------------
|
|
208
|
+
|
|
209
|
+
lkv "git stash" "pop"
|
|
210
|
+
|
|
211
|
+
git stash pop || exit_error "Failed to pop the stash into the hotfix"
|
|
212
|
+
|
|
213
|
+
lkv "git commit" "${MESSAGE}"
|
|
214
|
+
|
|
215
|
+
git commit -a -m"${MESSAGE}" || exit_error "Failed to commit the stash to ${HOTFIX_BRANCH}"
|
|
216
|
+
|
|
217
|
+
lkv "git commit succesful" "${HOTFIX_BRANCH}"
|
|
218
|
+
|
|
219
|
+
# ----------------------------------------------------------------------
|
|
220
|
+
# close the hotfix
|
|
221
|
+
# ----------------------------------------------------------------------
|
|
222
|
+
|
|
223
|
+
lkv "git flow hotfix finish" "${NEW_VERSION}"
|
|
224
|
+
|
|
225
|
+
git flow hotfix finish "${NEW_VERSION}" -m"${MESSAGE}" || exit_error "Failed to close ${HOTFIX_BRANCH}"
|
|
226
|
+
|
|
227
|
+
lkv "finished" "${HOTFIX_BRANCH}"
|
|
228
|
+
|
|
229
|
+
# closing the hotfix leaves you on the development branch
|
|
230
|
+
# return to the master ???? or should we stay on development
|
|
231
|
+
|
|
232
|
+
lkv "git checkout" "master"
|
|
233
|
+
|
|
234
|
+
git checkout master || exit_error "Failed to return to master branch"
|
|
235
|
+
|
|
236
|
+
# ----------------------------------------------------------------------
|
|
237
|
+
# now push the changes
|
|
238
|
+
# ----------------------------------------------------------------------
|
|
239
|
+
|
|
240
|
+
l_title 'Push Changes and Synchronize Master/Develop'
|
|
241
|
+
|
|
242
|
+
${SCRIPT_DIR}/${SYNC_SCRIPT}
|
|
243
|
+
|
|
244
|
+
l_heading 'Success'
|
data/bin/setup
ADDED
data/exe/macdiff
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
lib_path = File.expand_path('../lib', __dir__)
|
|
5
|
+
$LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include?(lib_path)
|
|
6
|
+
require 'macdiff/cli'
|
|
7
|
+
|
|
8
|
+
Signal.trap('INT') do
|
|
9
|
+
warn("\n#{caller.join("\n")}: interrupted")
|
|
10
|
+
exit(1)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
begin
|
|
14
|
+
Macdiff::CLI.start
|
|
15
|
+
rescue Macdiff::CLI::Error => e
|
|
16
|
+
puts "ERROR: #{e.message}"
|
|
17
|
+
exit 1
|
|
18
|
+
end
|
data/hooks/pre-commit
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require 'English'
|
|
5
|
+
|
|
6
|
+
# NOTE: you may need change file permissions
|
|
7
|
+
# chmod +x hooks/pre-commit
|
|
8
|
+
|
|
9
|
+
exit 0 if ARGV.include?('--no-verify')
|
|
10
|
+
|
|
11
|
+
warning_keywords = %w[console.log]
|
|
12
|
+
keywords = %w[binding.pry console.dir byebug debugger]
|
|
13
|
+
files_changed = `git diff-index --name-only HEAD --`.split
|
|
14
|
+
|
|
15
|
+
# puts '----------------------------------------------------------------------'
|
|
16
|
+
# puts remove files changed from the pre-commit checking if they are one of the following files
|
|
17
|
+
# puts '----------------------------------------------------------------------'
|
|
18
|
+
# files_changed = files_changed - ['hooks/pre-commit']
|
|
19
|
+
# files_changed = files_changed - ['hooks/update-version']
|
|
20
|
+
|
|
21
|
+
# byebug may need to be in these files
|
|
22
|
+
files_changed -= ['Gemfile']
|
|
23
|
+
files_changed -= ['Gemfile.lock']
|
|
24
|
+
files_changed -= ['.gitignore']
|
|
25
|
+
files_changed -= ['README.md']
|
|
26
|
+
|
|
27
|
+
files_changed = files_changed.reject { |f| f.downcase.end_with?('.json') }
|
|
28
|
+
files_changed = files_changed.reject { |f| f.downcase.end_with?('.yml') }
|
|
29
|
+
|
|
30
|
+
# ignore files from specific folders
|
|
31
|
+
|
|
32
|
+
file_groups = files_changed.select do |item|
|
|
33
|
+
item.start_with?('hooks') # ||
|
|
34
|
+
# item.start_with?('lib/generators')
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
files_changed -= file_groups
|
|
38
|
+
|
|
39
|
+
# remove files that are changed because they are deleted
|
|
40
|
+
files_changed = files_changed.select { |filename| File.file?(filename) }
|
|
41
|
+
|
|
42
|
+
# puts '----------------------------------------------------------------------'
|
|
43
|
+
# puts 'Files Changed'
|
|
44
|
+
# puts '----------------------------------------------------------------------'
|
|
45
|
+
# puts files_changed
|
|
46
|
+
# puts '----------------------------------------------------------------------'
|
|
47
|
+
|
|
48
|
+
unless files_changed.length.zero?
|
|
49
|
+
# puts "#{keywords.join('|')}"
|
|
50
|
+
# puts "#{files_changed.join(' ')}"
|
|
51
|
+
|
|
52
|
+
`git grep -q -E "#{warning_keywords.join('|')}" #{files_changed.join(' ')}`
|
|
53
|
+
|
|
54
|
+
if $CHILD_STATUS.exitstatus.zero?
|
|
55
|
+
puts '' # Check following lines:''
|
|
56
|
+
puts $CHILD_STATUS.exitstatus
|
|
57
|
+
files_changed.each do |file|
|
|
58
|
+
warning_keywords.each do |keyword|
|
|
59
|
+
# puts "#{keyword} ::: #{file}"
|
|
60
|
+
`git grep -q -E #{keyword} #{file}`
|
|
61
|
+
if $CHILD_STATUS.exitstatus.zero?
|
|
62
|
+
line = `git grep -n #{keyword} #{file} | awk -F ":" '{print $2}'`.split.join(', ')
|
|
63
|
+
puts "WARNING:\t\033[31m#{file}\033[0m contains #{keyword} at line \033[33m#{line}\033[0m."
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
`git grep -q -E "#{keywords.join('|')}" #{files_changed.join(' ')}`
|
|
70
|
+
|
|
71
|
+
if $CHILD_STATUS.exitstatus.zero?
|
|
72
|
+
puts '' # Check following lines:''
|
|
73
|
+
puts $CHILD_STATUS.exitstatus
|
|
74
|
+
files_changed.each do |file|
|
|
75
|
+
keywords.each do |keyword|
|
|
76
|
+
# puts "#{keyword} ::: #{file}"
|
|
77
|
+
`git grep -q -E #{keyword} #{file}`
|
|
78
|
+
if $CHILD_STATUS.exitstatus.zero?
|
|
79
|
+
line = `git grep -n #{keyword} #{file} | awk -F ":" '{print $2}'`.split.join(', ')
|
|
80
|
+
puts "ERROR :\t\033[31m#{file}\033[0m contains #{keyword} at line \033[33m#{line}\033[0m."
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
puts '# Force commit with --no-verify'
|
|
85
|
+
exit 1
|
|
86
|
+
end
|
|
87
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
# NOTE: you may need change file permissions
|
|
5
|
+
# chmod +x hooks/update-version
|
|
6
|
+
|
|
7
|
+
exit 1 if ARGV.empty?
|
|
8
|
+
|
|
9
|
+
version = ARGV[0]
|
|
10
|
+
version = version[1..-1] # revove 'v' character, e.g. v0.1.1 becomes 0.1.1
|
|
11
|
+
|
|
12
|
+
output = <<~RUBY
|
|
13
|
+
# frozen_string_literal: true
|
|
14
|
+
|
|
15
|
+
module Macdiff
|
|
16
|
+
VERSION = '#{version}'
|
|
17
|
+
end
|
|
18
|
+
RUBY
|
|
19
|
+
|
|
20
|
+
printf "%-25<label>s : %<version>s\n", label: 'GEM VERSION', version: version
|
|
21
|
+
File.open('lib/macdiff/version.rb', 'w+') { |f| f.write(output) }
|
data/lib/macdiff/app.rb
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'thor'
|
|
4
|
+
|
|
5
|
+
module Macdiff
|
|
6
|
+
# Handle the global access such as configuration
|
|
7
|
+
class App
|
|
8
|
+
attr_reader :config
|
|
9
|
+
|
|
10
|
+
def initialize
|
|
11
|
+
@config = TTY::Config.new
|
|
12
|
+
@config.filename = 'macdiff'
|
|
13
|
+
@config.extname = '.yml'
|
|
14
|
+
# @config.append_path Dir.pwd # Dir.home
|
|
15
|
+
@config.append_path File.join(Dir.home, '.config')
|
|
16
|
+
@config.write unless @config.exist?
|
|
17
|
+
@config.read
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.config
|
|
21
|
+
@config ||= new.config
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
data/lib/macdiff/cli.rb
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'thor'
|
|
4
|
+
|
|
5
|
+
module Macdiff
|
|
6
|
+
# Handle the application command line parsing
|
|
7
|
+
# and the dispatch to various command objects
|
|
8
|
+
#
|
|
9
|
+
# @api public
|
|
10
|
+
class CLI < Thor
|
|
11
|
+
# Error raised by this runner
|
|
12
|
+
Error = Class.new(StandardError)
|
|
13
|
+
|
|
14
|
+
desc 'version', 'macdiff version'
|
|
15
|
+
def version
|
|
16
|
+
require_relative 'version'
|
|
17
|
+
puts 'v' + Macdiff::VERSION
|
|
18
|
+
end
|
|
19
|
+
map %w[--version -v] => :version
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'app'
|
|
4
|
+
require 'forwardable'
|
|
5
|
+
require 'pastel'
|
|
6
|
+
|
|
7
|
+
module Macdiff
|
|
8
|
+
# Base command class
|
|
9
|
+
class Command
|
|
10
|
+
extend Forwardable
|
|
11
|
+
|
|
12
|
+
attr_reader :pastel
|
|
13
|
+
# attr_reader :my_config_setting
|
|
14
|
+
|
|
15
|
+
def_delegators :command, :run
|
|
16
|
+
|
|
17
|
+
def initialize(options)
|
|
18
|
+
@options = options
|
|
19
|
+
@pastel = Pastel.new
|
|
20
|
+
config
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# ----------------------------------------------------------------------
|
|
24
|
+
# Commandlet configuration helpers
|
|
25
|
+
# ----------------------------------------------------------------------
|
|
26
|
+
|
|
27
|
+
# Commandlet Configuration
|
|
28
|
+
def config
|
|
29
|
+
config = Macdiff::App.config
|
|
30
|
+
|
|
31
|
+
# @my_config_setting = config.fetch(:my_config_setting)
|
|
32
|
+
|
|
33
|
+
config
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Configuration set key/value
|
|
37
|
+
#
|
|
38
|
+
# example:
|
|
39
|
+
# set(:name, 'David')
|
|
40
|
+
def config_set(key, value)
|
|
41
|
+
config.read
|
|
42
|
+
config.set(key, value: value)
|
|
43
|
+
config.write force: true
|
|
44
|
+
value
|
|
45
|
+
end
|
|
46
|
+
alias set config_set
|
|
47
|
+
|
|
48
|
+
# Configuration fetch key/value
|
|
49
|
+
#
|
|
50
|
+
# example:
|
|
51
|
+
# get(:name) ==> 'David'
|
|
52
|
+
def config_fetch(key)
|
|
53
|
+
config.read
|
|
54
|
+
config.fetch(key)
|
|
55
|
+
end
|
|
56
|
+
alias get config_fetch
|
|
57
|
+
|
|
58
|
+
# ----------------------------------------------------------------------
|
|
59
|
+
# Screen rendering helpers
|
|
60
|
+
# ----------------------------------------------------------------------
|
|
61
|
+
|
|
62
|
+
# kv - Print Key/Value
|
|
63
|
+
def kv(key, value, key_width = 30)
|
|
64
|
+
puts "#{pastel.green(key.ljust(key_width))}: #{value}"
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def line(size = 70, character = '=')
|
|
68
|
+
result = character * size
|
|
69
|
+
puts pastel.green(result)
|
|
70
|
+
end
|
|
71
|
+
alias l line
|
|
72
|
+
|
|
73
|
+
def heading(heading, size = 70)
|
|
74
|
+
line(size)
|
|
75
|
+
puts heading
|
|
76
|
+
line(size)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def subheading(heading, size = 70)
|
|
80
|
+
line(size, '-')
|
|
81
|
+
puts heading
|
|
82
|
+
line(size, '-')
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# A section heading
|
|
86
|
+
#
|
|
87
|
+
# example:
|
|
88
|
+
# [ I am a heading ]----------------------------------------------------
|
|
89
|
+
def section_heading(heading, size = 70)
|
|
90
|
+
section_heading = "[ #{heading} ]#{'-' * (size - heading.length)}"
|
|
91
|
+
|
|
92
|
+
puts pastel.green(section_heading)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def pretty_print(obj)
|
|
96
|
+
puts JSON.pretty_generate obj
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def print_all(data)
|
|
100
|
+
keys = data.first.keys
|
|
101
|
+
data.each do |row|
|
|
102
|
+
keys.each do |key|
|
|
103
|
+
puts "#{key.to_s.rjust(20)}: #{row[key].to_s.delete("\n")[1..100]}"
|
|
104
|
+
end
|
|
105
|
+
puts '-' * 120
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Print a pretty table
|
|
110
|
+
#
|
|
111
|
+
# Example:
|
|
112
|
+
# values = [
|
|
113
|
+
# ['less', which('less')],
|
|
114
|
+
# ['ruby', which('ruby')]
|
|
115
|
+
# ]
|
|
116
|
+
# pretty_table('Which paths', %w[key path], values)
|
|
117
|
+
def pretty_table(heading, column_headings, column_values)
|
|
118
|
+
heading heading
|
|
119
|
+
|
|
120
|
+
require 'tty-table'
|
|
121
|
+
table = TTY::Table.new column_headings, column_values
|
|
122
|
+
puts table.render(:unicode, multiline: true, resize: true)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# ----------------------------------------------------------------------
|
|
126
|
+
# Access to TTY helpers
|
|
127
|
+
# ----------------------------------------------------------------------
|
|
128
|
+
|
|
129
|
+
# Execute this command
|
|
130
|
+
#
|
|
131
|
+
# @api public
|
|
132
|
+
def execute(*)
|
|
133
|
+
raise(
|
|
134
|
+
NotImplementedError,
|
|
135
|
+
"#{self.class}##{__method__} must be implemented"
|
|
136
|
+
)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
# The external commands runner
|
|
140
|
+
#
|
|
141
|
+
# @see http://www.rubydoc.info/gems/tty-command
|
|
142
|
+
#
|
|
143
|
+
# @api public
|
|
144
|
+
def command(**options)
|
|
145
|
+
require 'tty-command'
|
|
146
|
+
TTY::Command.new(options)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
# The cursor movement
|
|
150
|
+
#
|
|
151
|
+
# @see http://www.rubydoc.info/gems/tty-cursor
|
|
152
|
+
#
|
|
153
|
+
# @api public
|
|
154
|
+
def cursor
|
|
155
|
+
require 'tty-cursor'
|
|
156
|
+
TTY::Cursor
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def clear_screen
|
|
160
|
+
puts cursor.clear_screen
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
# Open a file or text in the user's preferred editor
|
|
164
|
+
#
|
|
165
|
+
# @see http://www.rubydoc.info/gems/tty-editor
|
|
166
|
+
#
|
|
167
|
+
# @api public
|
|
168
|
+
def editor
|
|
169
|
+
require 'tty-editor'
|
|
170
|
+
TTY::Editor
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
# File manipulation utility methods
|
|
174
|
+
#
|
|
175
|
+
# @see http://www.rubydoc.info/gems/tty-file
|
|
176
|
+
#
|
|
177
|
+
# @api public
|
|
178
|
+
def generator
|
|
179
|
+
require 'tty-file'
|
|
180
|
+
TTY::File
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
# Terminal output paging
|
|
184
|
+
#
|
|
185
|
+
# @see http://www.rubydoc.info/gems/tty-pager
|
|
186
|
+
#
|
|
187
|
+
# @api public
|
|
188
|
+
def pager(**options)
|
|
189
|
+
require 'tty-pager'
|
|
190
|
+
TTY::Pager.new(options)
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
# Terminal platform and OS properties
|
|
194
|
+
#
|
|
195
|
+
# @see http://www.rubydoc.info/gems/tty-pager
|
|
196
|
+
#
|
|
197
|
+
# @api public
|
|
198
|
+
def platform
|
|
199
|
+
require 'tty-platform'
|
|
200
|
+
TTY::Platform.new
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
# The interactive prompt
|
|
204
|
+
#
|
|
205
|
+
# @see http://www.rubydoc.info/gems/tty-prompt
|
|
206
|
+
#
|
|
207
|
+
# @api public
|
|
208
|
+
def prompt(**options)
|
|
209
|
+
require 'tty-prompt'
|
|
210
|
+
TTY::Prompt.new(options)
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
# Get terminal screen properties
|
|
214
|
+
#
|
|
215
|
+
# @see http://www.rubydoc.info/gems/tty-screen
|
|
216
|
+
#
|
|
217
|
+
# @api public
|
|
218
|
+
def screen
|
|
219
|
+
require 'tty-screen'
|
|
220
|
+
TTY::Screen
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
# The unix which utility
|
|
224
|
+
#
|
|
225
|
+
# @see http://www.rubydoc.info/gems/tty-which
|
|
226
|
+
#
|
|
227
|
+
# @api public
|
|
228
|
+
def which(*args)
|
|
229
|
+
require 'tty-which'
|
|
230
|
+
TTY::Which.which(*args)
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
# Check if executable exists
|
|
234
|
+
#
|
|
235
|
+
# @see http://www.rubydoc.info/gems/tty-which
|
|
236
|
+
#
|
|
237
|
+
# @api public
|
|
238
|
+
def exec_exist?(*args)
|
|
239
|
+
require 'tty-which'
|
|
240
|
+
TTY::Which.exist?(*args)
|
|
241
|
+
end
|
|
242
|
+
end
|
|
243
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|