markdown_exec 0.2.5 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 95d097cfcf93e09ba3bf487989923d4be03dd9fde0521854ea0660850b157d01
4
- data.tar.gz: 22bc0e8bc8cd35d0d1dd52b6275c1609fb4cb95d69bd125064f0ca16f2f931f7
3
+ metadata.gz: d34e8e9ff237ed338e50c0a03dfbb8c4bbd10e49f1f6ee54f54607ce19b96632
4
+ data.tar.gz: 54f0ce617360be38233ed974f2cb8d5656e1b9f7671ed9f2ac819c2d66843eb1
5
5
  SHA512:
6
- metadata.gz: 591c09a221c0f5a34f8523d99d8e416bb022219fee38a7a05e3541600b03132e5ae3cc6aee02048eda2170a408d9e86090dedadff7c16f1f79ea98469826c27a
7
- data.tar.gz: 74a76b6a6b10b165f8e79e59d25db78bcba173d730fd1a696e73c2012794bcfedd7c1b648cabe6b15d4d0a70995e5303b02c58d0b16c35a03ffbfea0b4efc5f4
6
+ metadata.gz: e14f9203dd2c07b0b0fef5a71ebec355d1e1988c798bc0f5811bf6b97a0f8cd52066ff4dee2372c522248a920add287e3ac8567b3a68d7b885a3ec42266faa30
7
+ data.tar.gz: b843ddd2e4b7b1b8eda9b4eb19823a32f758a422e27f84a779372e22321f4b16ce3307f51abb45e7bdbf92d14311ceedd110a1999203ffcf03ccb0ffa8f93b7e
data/CHANGELOG.md CHANGED
@@ -2,27 +2,89 @@
2
2
 
3
3
  ## [ToDo]
4
4
 
5
- - pipe stdin to script
6
- - yes/no/write/clipboard/record/edit/history
7
- - present timestamp, result of last exec for each command
8
5
  - user settings
9
6
  - hidden w , w/o () in names
10
7
  - fix regexp in pathnames
11
- - tab completion from md file
12
- - read file once to allow for tempdoc stream
13
- - include md or blocks file
8
+
9
+ - [ ] read file once to allow for tempdoc stream
14
10
 
15
11
  - tree display
16
12
 
17
- - mde options in md file or included file
13
+ - [ ] mde options, user prompt, in md file or included file
14
+
15
+ - [ ] include blocks from local md file
16
+
17
+ - execute? yes/no/save/clipboard + record/edit/history
18
+
19
+ - [ ] list, view saved output
20
+
21
+ - completion
22
+ - [ ] include blocks in md file
23
+
24
+ - [ ] ruby gem data model
25
+
26
+ - [ ] extract yaml block into stdout
27
+ - [ ] extract json block into stdout
28
+
29
+ - [ ] import yaml, json data into environment
30
+
31
+ - [ ] yq filter with imported or named yaml, json data
32
+
33
+ - [ ] yaml dump of options w/ detail
34
+
35
+ - [ ] re-exec last script v re-run named block in last script
36
+ - [ ] repeat to reload last doc and block
37
+ - [ ] option to output mixed stdin, stdout, stderr; labels: prefix and blocks
38
+
39
+ ## [1.0.1] - 2022-05-21
40
+
41
+ ### Added
42
+
43
+ - Display administrative output (command, save files) for executed blocks.
44
+ - Select base, administrative output as hierarchical output (MDE_DISPLAY_LEVEL).
45
+ - The user may select Exit, the first option, to quit the program.
46
+ - The block-selection menu is re-displayed after an approved script is exectued.
47
+ - Pause for and pass through standard input in scripts executed by the tool.
48
+ - Options
49
+ - chmod for saved scripts
50
+ - shebang for saved scripts
51
+ - shell for executed and saved scripts
52
+
53
+ ### Changed
18
54
 
19
- - include blocks from local md file
55
+ - Exit option is at top of each menu.
56
+ - Single-stage tab completion, defaut
57
+ - Presents matching options when current word starts with `-`
58
+ - Presents directories and files otherwise.
59
+ - Two-stage tab completion for option arguments.
60
+ - When prior word is an option and current word is empty
61
+ - Presents option type on first tab, eg `.BOOL.` for a boolean option.
62
+ - Presents option default value on second tab, eg `0` for false.
63
+ - Use 'bash' shell instead of default
64
+ - Write STDOUT, STDERR, STDIN in sections to saved output file.
65
+
66
+ ## [1.0.0] - 2022-04-26
67
+
68
+ ### Added
20
69
 
21
- - chmod a+x logged script
70
+ - Command `--pwd` to print the gem's home folder.
71
+ - Command `--select-recent-output` to select and open a recent output log file.
72
+ e.g. `MDE_OUTPUT_VIEWER_OPTIONS="-a '/Applications/Sublime Text.app'" mde --select-recent-output`
73
+ - Command `--tab-completions` to list the application options.
74
+ - Tab completion script for Bash shell.
75
+
76
+ ### Changed
77
+
78
+ - File names for saved scripts.
79
+ - Hide blocks with empty names, e.g. `:()`.
80
+
81
+ ## [0.2.6] - 2022-04-07
82
+
83
+ ### Changed
22
84
 
23
- - add shebang to saved script
85
+ - Default values for command line options.
24
86
 
25
- ## [0.2.5] - 2022-04
87
+ ## [0.2.5] - 2022-04-03
26
88
 
27
89
  ### Added
28
90
 
data/Gemfile CHANGED
@@ -2,13 +2,14 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
- # Specify your gem's dependencies in markdown_exec.gemspec
6
5
  gemspec
7
-
8
- gem 'rake', '~> 13.0'
9
-
6
+ gem 'clipboard'
7
+ gem 'erb'
10
8
  gem 'minitest', '~> 5.0'
11
-
9
+ gem 'rake', '~> 13.0'
12
10
  gem 'rubocop', '~> 1.21'
13
11
  gem 'rubocop-minitest', require: false
14
12
  gem 'rubocop-rake', require: false
13
+ gem 'shellwords'
14
+ gem 'uri'
15
+ gem 'yaml'
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- markdown_exec (0.2.5)
4
+ markdown_exec (1.1.0)
5
+ clipboard (~> 1.3.6)
5
6
  open3 (~> 0.1.1)
6
7
  optparse (~> 0.1.1)
7
8
  tty-prompt (~> 0.23.1)
@@ -11,6 +12,10 @@ GEM
11
12
  remote: https://rubygems.org/
12
13
  specs:
13
14
  ast (2.4.2)
15
+ cgi (0.3.2)
16
+ clipboard (1.3.6)
17
+ erb (2.2.3)
18
+ cgi
14
19
  minitest (5.15.0)
15
20
  open3 (0.1.1)
16
21
  optparse (0.1.1)
@@ -39,6 +44,7 @@ GEM
39
44
  rubocop-rake (0.6.0)
40
45
  rubocop (~> 1.0)
41
46
  ruby-progressbar (1.11.0)
47
+ shellwords (0.1.0)
42
48
  tty-color (0.6.0)
43
49
  tty-cursor (0.7.1)
44
50
  tty-prompt (0.23.1)
@@ -50,6 +56,7 @@ GEM
50
56
  wisper (~> 2.0)
51
57
  tty-screen (0.8.1)
52
58
  unicode-display_width (2.1.0)
59
+ uri (0.11.0)
53
60
  wisper (2.0.1)
54
61
  yaml (0.2.0)
55
62
 
@@ -57,12 +64,17 @@ PLATFORMS
57
64
  arm64-darwin-21
58
65
 
59
66
  DEPENDENCIES
67
+ clipboard
68
+ erb
60
69
  markdown_exec!
61
70
  minitest (~> 5.0)
62
71
  rake (~> 13.0)
63
72
  rubocop (~> 1.21)
64
73
  rubocop-minitest
65
74
  rubocop-rake
75
+ shellwords
76
+ uri
77
+ yaml
66
78
 
67
79
  BUNDLED WITH
68
80
  2.2.32
data/README.md CHANGED
@@ -55,6 +55,10 @@ Process `README.md` file in the current folder. Displays all the blocks in the f
55
55
 
56
56
  Select a block to execute from `my.md`.
57
57
 
58
+ #### `mde my.md myblock`
59
+
60
+ Execute the block named `myblock` from `my.md`.
61
+
58
62
  #### `mde .` or `mde -p .`
59
63
 
60
64
  Select a markdown file in the current folder. Select a block to execute from that file.
@@ -142,7 +146,27 @@ Boolean options configured with environment variables:
142
146
  - Specify variable on command line.
143
147
  e.g. `MDE_SAVE_EXECUTED_SCRIPT=1 mde`
144
148
 
145
- # Example blocks
149
+ ## Tab Completion
150
+
151
+ ### Install tab completion
152
+
153
+ Append a command to load the completion script to your shell configuration file. `mde` must be executable for the command to be composed correctly.
154
+
155
+ ```bash :()
156
+ echo "source $(mde --pwd)/bin/tab_completion.sh" >> ~/.bash_profile
157
+ ```
158
+
159
+ ### Example Completions
160
+
161
+ Type tab at end of any of the following commands to see the options.
162
+ - `mde `
163
+ - `mde -`
164
+ - `mde --`
165
+ - `mde --o`
166
+ - `mde --filename my.md -`
167
+ - `mde --filename my.md --`
168
+
169
+ ## Example Blocks
146
170
 
147
171
  When prompted, select either the `awake` or `asleep` block.
148
172
 
@@ -166,17 +190,6 @@ export ACTIVITY=asleep
166
190
  echo "$TIME -> $ACTIVITY"
167
191
  ```
168
192
 
169
- ``` :missing_command
170
- fail
171
- ```
172
-
173
- ``` :exit_value
174
- echo "a"
175
- echo "b"
176
- echo "c" >>/dev/stderr
177
- grep nx Gemfile
178
- ```
179
-
180
193
  # License
181
194
 
182
195
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -184,3 +197,34 @@ The gem is available as open source under the terms of the [MIT License](https:/
184
197
  # Code of Conduct
185
198
 
186
199
  Everyone interacting in the MarkdownExec project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/markdown_exec/blob/master/CODE_OF_CONDUCT.md).
200
+
201
+ ###
202
+ i made a tool to help me execute shell commands for ansible, aws, etc.
203
+
204
+ normally the scripts have a base configuration followed by one or more blocks of commands that must be executed with the base configuration.
205
+
206
+ by storing the shell scripts in a markdown file, there is room for both code and explanatory text. the tool provides the interface that names all the code blocks in the file and allows the the user to select and preview the code to execute.
207
+
208
+ i use it regularly to manage deployment processes that require dozens of steps with ease and re-playablity.
209
+
210
+ the gem is hosted at `https://github.com/fareedst/markdown_exec`.
211
+
212
+ please install the Ruby gem with `gem install markdown_exec` and let me know how the installation goes for you. i would like to see if your current deployment scripts can fit into this model.
213
+
214
+ ```bash :test1
215
+ files="$(ls -A .)"
216
+ PS3='?'
217
+ select filename in ${files}; do echo "You selected ${filename}"; break; done
218
+
219
+ echo "-1"
220
+ echo $0
221
+ echo 'AA'
222
+ echo 'name? '
223
+ read name
224
+ echo 'type? '
225
+ read type
226
+ echo 'BB'
227
+ echo "name: $name"
228
+ echo "type: $type"
229
+ echo 'CC'
230
+ ```
data/Rakefile CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  require 'bundler/gem_tasks'
4
4
  require 'rake/testtask'
5
+ require 'erb'
6
+ require 'yaml'
7
+
8
+ require_relative 'lib/shared'
5
9
 
6
10
  Rake::TestTask.new(:test) do |task|
7
11
  task.libs << 'test'
@@ -12,7 +16,7 @@ end
12
16
  require 'rubocop/rake_task'
13
17
 
14
18
  RuboCop::RakeTask.new do |task|
15
- # task.requires << 'rubocop-minitest'
19
+ task.requires << 'rubocop-minitest'
16
20
  end
17
21
 
18
22
  desc 'named task because minitest not included in rubocop tests'
@@ -50,3 +54,33 @@ desc 'gem build clean'
50
54
  task :clean do
51
55
  system 'rm *.gem'
52
56
  end
57
+
58
+ private
59
+
60
+ BF = 'bin'
61
+
62
+ def update_tab_completion(target)
63
+ words = `#{File.join BF, MarkdownExec::BIN_NAME} --tab-completions`.split("\n")
64
+ mde_tab_completions = '(' + (words.map { |s| "\"#{s}\"" }).join(' ') + ')'
65
+ mde_help = `#{File.join BF, MarkdownExec::BIN_NAME} --help`.split("\n")
66
+ menu_export_yaml = `#{File.join BF, MarkdownExec::BIN_NAME} --menu-export`
67
+
68
+ svhs = YAML.load menu_export_yaml # rubocop:disable Security/YAMLLoad
69
+ svhs.each do |svh|
70
+ svh[:compreply] = value_for_cli(svh[:default]) if svh[:compreply].nil?
71
+ end.tap_inspect name: :svhs, format: :yaml
72
+
73
+ File.write target, ERB.new(File.read(File.join(BF, 'tab_completion.sh.erb'))).result(binding)
74
+ end
75
+
76
+ desc 'update tab_completion.sh'
77
+ task :update_tab_completion do
78
+ update_tab_completion File.join(BF, 'tab_completion.sh')
79
+ end
80
+
81
+ desc 'update tab_completion.sh'
82
+ task :update_installed_tab_completion do
83
+ update_tab_completion(fs = File.join(`mde --pwd`.chomp, BF, 'tab_completion.sh'))
84
+
85
+ puts `cat #{fs}` ###
86
+ end
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,143 @@
1
+ #!/usr/bin/env bash
2
+
3
+ __filedirs()
4
+ {
5
+ local IFS=$'\n'
6
+ COMPREPLY=( $(compgen -o plusdirs -f -- "${cur}") )
7
+ # COMPREPLY=( $(compgen -d) $(compgen -f -- "${cur}") )
8
+ }
9
+
10
+ __filedirs_all()
11
+ {
12
+ COMPREPLY='.'
13
+ }
14
+
15
+ _mde_echo_version() {
16
+ echo "1.1.0"
17
+ }
18
+
19
+ _mde() {
20
+ local cur prev opts
21
+ cur="${COMP_WORDS[COMP_CWORD]}"
22
+ prev="${COMP_WORDS[COMP_CWORD-1]}"
23
+ # printf '%s' "-;${prev}-:${cur}-"
24
+
25
+ # current word is an option type
26
+ # if previous word is an option name
27
+ # stage 2: replace with option default value
28
+ #
29
+ if [[ "${cur}" =~ ^\..+\.$ ]] ; then
30
+ if [[ ${prev} == -* ]] ; then
31
+ case $prev in
32
+
33
+ --config) COMPREPLY="."; return 0 ;;
34
+
35
+ --debug) COMPREPLY="0"; return 0 ;;
36
+
37
+ --display-level) COMPREPLY="1"; return 0 ;;
38
+
39
+ --filename) COMPREPLY="."; return 0 ;;
40
+
41
+ --list-count) COMPREPLY="32"; return 0 ;;
42
+
43
+ --logged-stdout-filename-prefix) COMPREPLY="mde"; return 0 ;;
44
+
45
+ --output-execution-summary) COMPREPLY="0"; return 0 ;;
46
+
47
+ --output-script) COMPREPLY="0"; return 0 ;;
48
+
49
+ --output-stdout) COMPREPLY="1"; return 0 ;;
50
+
51
+ --path) COMPREPLY="."; return 0 ;;
52
+
53
+ --save-executed-script) COMPREPLY="0"; return 0 ;;
54
+
55
+ --save-execution-output) COMPREPLY="0"; return 0 ;;
56
+
57
+ --saved-script-chmod) COMPREPLY="493"; return 0 ;;
58
+
59
+ --saved-script-filename-prefix) COMPREPLY="mde"; return 0 ;;
60
+
61
+ --saved-script-folder) COMPREPLY="logs"; return 0 ;;
62
+
63
+ --saved-script-glob) COMPREPLY="mde_\*.sh"; return 0 ;;
64
+
65
+ --saved-stdout-folder) COMPREPLY="logs"; return 0 ;;
66
+
67
+ --saved-stdout-glob) COMPREPLY="mde_\*.out.txt"; return 0 ;;
68
+
69
+ --user-must-approve) COMPREPLY="1"; return 0 ;;
70
+
71
+ esac
72
+ fi
73
+ fi
74
+
75
+ # current word is an option name or start of
76
+ # present matching option names
77
+ #
78
+ if [[ ${cur} == -* ]] ; then
79
+ opts=("--list-blocks" "--list-default-env" "--list-default-yaml" "--list-docs" "--list-recent-output" "--list-recent-scripts" "--pwd" "--run-last-script" "--select-recent-output" "--select-recent-script" "--menu-export" "--tab-completions" "--help" "--version" "--exit" "--config" "--debug" "--display-level" "--block-name" "--filename" "--list-count" "--logged-stdout-filename-prefix" "--output-execution-summary" "--output-script" "--output-stdout" "--path" "--save-executed-script" "--save-execution-output" "--saved-script-chmod" "--saved-script-filename-prefix" "--saved-script-folder" "--saved-script-glob" "--saved-stdout-folder" "--saved-stdout-glob" "--user-must-approve")
80
+ COMPREPLY=( $(compgen -W "$(printf "'%s' " "${opts[@]}")" -- "${cur}") )
81
+
82
+ return 0
83
+ fi
84
+
85
+ # no current word
86
+ # if previous word is an option name
87
+ # stage 1: present option type
88
+ #
89
+ if [[ -z ${cur} ]] ; then
90
+ case $prev in
91
+
92
+ --config) COMPREPLY=".PATH."; return 0 ;;
93
+
94
+ --debug) COMPREPLY=".BOOL."; return 0 ;;
95
+
96
+ --display-level) COMPREPLY=".INT.0-2."; return 0 ;;
97
+
98
+ --block-name) COMPREPLY=".NAME."; return 0 ;;
99
+
100
+ --filename) COMPREPLY=".RELATIVE_PATH."; return 0 ;;
101
+
102
+ --list-count) COMPREPLY=".INT.1-."; return 0 ;;
103
+
104
+ --logged-stdout-filename-prefix) COMPREPLY=".PREFIX."; return 0 ;;
105
+
106
+ --output-execution-summary) COMPREPLY=".BOOL."; return 0 ;;
107
+
108
+ --output-script) COMPREPLY=".BOOL."; return 0 ;;
109
+
110
+ --output-stdout) COMPREPLY=".BOOL."; return 0 ;;
111
+
112
+ --path) COMPREPLY=".RELATIVE_PATH."; return 0 ;;
113
+
114
+ --save-executed-script) COMPREPLY=".BOOL."; return 0 ;;
115
+
116
+ --save-execution-output) COMPREPLY=".BOOL."; return 0 ;;
117
+
118
+ --saved-script-chmod) COMPREPLY=".INT."; return 0 ;;
119
+
120
+ --saved-script-filename-prefix) COMPREPLY=".PREFIX."; return 0 ;;
121
+
122
+ --saved-script-folder) COMPREPLY=".RELATIVE_PATH."; return 0 ;;
123
+
124
+ --saved-script-glob) COMPREPLY=".GLOB."; return 0 ;;
125
+
126
+ --saved-stdout-folder) COMPREPLY=".RELATIVE_PATH."; return 0 ;;
127
+
128
+ --saved-stdout-glob) COMPREPLY=".GLOB."; return 0 ;;
129
+
130
+ --user-must-approve) COMPREPLY=".BOOL."; return 0 ;;
131
+
132
+ esac
133
+ fi
134
+
135
+ # current word is unrecognized
136
+ # present matching directory or file names
137
+ #
138
+ __filedirs
139
+ }
140
+
141
+ complete -o filenames -o nospace -F _mde mde
142
+ # _mde_echo_version
143
+ # echo "Updated: 2022-05-21 16:42:10 UTC"
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env bash
2
+
3
+ __filedirs()
4
+ {
5
+ local IFS=$'\n'
6
+ COMPREPLY=( $(compgen -o plusdirs -f -- "${cur}") )
7
+ # COMPREPLY=( $(compgen -d) $(compgen -f -- "${cur}") )
8
+ }
9
+
10
+ __filedirs_all()
11
+ {
12
+ COMPREPLY='.'
13
+ }
14
+
15
+ _mde_echo_version() {
16
+ echo "<%= MarkdownExec::VERSION %>"
17
+ }
18
+
19
+ _mde() {
20
+ local cur prev opts
21
+ cur="${COMP_WORDS[COMP_CWORD]}"
22
+ prev="${COMP_WORDS[COMP_CWORD-1]}"
23
+ # printf '%s' "-;${prev}-:${cur}-"
24
+
25
+ # current word is an option type
26
+ # if previous word is an option name
27
+ # stage 2: replace with option default value
28
+ #
29
+ if [[ "${cur}" =~ ^\..+\.$ ]] ; then
30
+ if [[ ${prev} == -* ]] ; then
31
+ case $prev in
32
+ <% svhs.each do |svh|
33
+ svn = svh[:long_name]
34
+ if svn && svh[:arg_name]
35
+ svn = '--' + svh[:long_name]
36
+ if svh[:compreply] == false
37
+ # nothing
38
+ elsif svh[:compreply].nil? %>
39
+ <%= svn + ') __filedirs_all; return 0 ;;' %>
40
+ <% elsif svh[:compreply].empty?
41
+ # nothing
42
+ else %>
43
+ <%= svn + ') COMPREPLY="' + svh[:compreply] + '"; return 0 ;;' %>
44
+ <% end
45
+ end
46
+ end %>
47
+ esac
48
+ fi
49
+ fi
50
+
51
+ # current word is an option name or start of
52
+ # present matching option names
53
+ #
54
+ if [[ ${cur} == -* ]] ; then
55
+ opts=<%= mde_tab_completions %>
56
+ COMPREPLY=( $(compgen -W "$(printf "'%s' " "${opts[@]}")" -- "${cur}") )
57
+
58
+ return 0
59
+ fi
60
+
61
+ # no current word
62
+ # if previous word is an option name
63
+ # stage 1: present option type
64
+ #
65
+ if [[ -z ${cur} ]] ; then
66
+ case $prev in
67
+ <% svhs.each do |svh|
68
+ svn = svh[:long_name]
69
+ if svn && svh[:arg_name]
70
+ svn = '--' + svh[:long_name] %>
71
+ <%= svn + ') COMPREPLY=".' + svh[:arg_name] + '."; return 0 ;;' %>
72
+ <% end
73
+ end %>
74
+ esac
75
+ fi
76
+
77
+ # current word is unrecognized
78
+ # present matching directory or file names
79
+ #
80
+ __filedirs
81
+ }
82
+
83
+ complete -o filenames -o nospace -F _mde mde
84
+ # _mde_echo_version
85
+ # echo "Updated: <%= Time.now.utc %>"
@@ -1,8 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MarkdownExec
4
- APP_NAME = 'MDE'
5
4
  APP_DESC = 'Markdown Executor'
5
+ APP_NAME = 'MDE'
6
+ BIN_NAME = 'mde'
6
7
  GEM_NAME = 'markdown_exec'
7
- VERSION = '0.2.5'
8
+ VERSION = '1.1.0'
8
9
  end