markdown_exec 0.2.1 → 0.2.5

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: 7a2b550aaccca7d0752e57c39808f5d8d3b889b9d74cf3330dee6832b2f6c535
4
- data.tar.gz: 1296490dd79071f78b5009cb843c911fe822257ed148b4c1a516366eb02407ca
3
+ metadata.gz: 95d097cfcf93e09ba3bf487989923d4be03dd9fde0521854ea0660850b157d01
4
+ data.tar.gz: 22bc0e8bc8cd35d0d1dd52b6275c1609fb4cb95d69bd125064f0ca16f2f931f7
5
5
  SHA512:
6
- metadata.gz: 43f659be4397e4bb24811a8219de7b58e9665aa8751063281e2cfbbf94263ceda15f411a34fe31293869f0bbdba761c2afce72ea7f800b54edba75424313bd19
7
- data.tar.gz: bd48ac8a5ebedbc8b92af6345743d1bd6cf50705d05769e7144ccad998ddf0f00de72366779cb654a4272c3cc2f044c4c7e46ae9df935dcb4fc486a67e54453e
6
+ metadata.gz: 591c09a221c0f5a34f8523d99d8e416bb022219fee38a7a05e3541600b03132e5ae3cc6aee02048eda2170a408d9e86090dedadff7c16f1f79ea98469826c27a
7
+ data.tar.gz: 74a76b6a6b10b165f8e79e59d25db78bcba173d730fd1a696e73c2012794bcfedd7c1b648cabe6b15d4d0a70995e5303b02c58d0b16c35a03ffbfea0b4efc5f4
data/.rubocop.yml CHANGED
@@ -1,4 +1,9 @@
1
+ require:
2
+ - rubocop-minitest
3
+ - rubocop-rake
4
+
1
5
  AllCops:
6
+ NewCops: enable
2
7
  TargetRubyVersion: 2.6
3
8
 
4
9
  Metrics/AbcSize:
data/CHANGELOG.md CHANGED
@@ -1,4 +1,135 @@
1
- ## [Unreleased]
1
+ # Changelog
2
+
3
+ ## [ToDo]
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
+ - user settings
9
+ - hidden w , w/o () in names
10
+ - 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
14
+
15
+ - tree display
16
+
17
+ - mde options in md file or included file
18
+
19
+ - include blocks from local md file
20
+
21
+ - chmod a+x logged script
22
+
23
+ - add shebang to saved script
24
+
25
+ ## [0.2.5] - 2022-04
26
+
27
+ ### Added
28
+
29
+ - Command `--list-default-env` to show default configuration as environment variables.
30
+ - Command `--list-default-yaml` to show default configuration as YAML.
31
+ - Option to exit program when selecting files or blocks.
32
+
33
+ ### Changed
34
+
35
+ - Composition of menu to facilitate reports.
36
+ - List default values in menu help.
37
+
38
+ ## [0.2.4] - 2022-04-01
39
+
40
+ ### Added
41
+
42
+ - Command `--list-recent-scripts` to list the last *N* saved scripts.
43
+ - Command `--run-last-script` to re-run the last saved script.
44
+ - Command `--select-recent-script` to select and execute a recently saved script.
45
+
46
+ | YAML Name | Environment Variable | Option Name | Default | Purpose |
47
+ | :--- | :--- | :--- | :--- | :--- |
48
+ | list_count | MDE_LIST_COUNT | `--list-count` | `16` | Max. items to return in list |
49
+ | logged_stdout_filename_prefix | MDE_LOGGED_STDOUT_FILENAME_PREFIX | | `mde` | Name prefix for stdout files |
50
+ | save_execution_output | MDE_SAVE_EXECUTION_OUTPUT | `--save-execution-output` | False | Save standard output of the executed script |
51
+ | saved_script_filename_prefix | MDE_SAVED_SCRIPT_FILENAME_PREFIX | | `mde` | Name prefix for saved scripts |
52
+ | saved_script_folder | MDE_SAVED_SCRIPT_FOLDER | `--saved-script-folder` | `logs` | Saved script folder |
53
+ | saved_script_glob | MDE_SAVED_SCRIPT_GLOB | | `mde_*.sh` | Glob matching saved scripts |
54
+ | saved_stdout_folder | MDE_SAVED_STDOUT_FOLDER | `--saved-stdout-folder` | `logs` | Saved stdout folder |
55
+
56
+ ### Changed
57
+
58
+ - Fix saving of executed script.
59
+ - Sort configuration keys output by `-0` (Show configuration.)
60
+
61
+ ## [0.2.3] - 2022-03-29
62
+
63
+ ### Added
64
+
65
+ - `rubocop` checks.
66
+ - Added optional command-line positional arguments:
67
+ 1. document file
68
+ 2. block name
69
+
70
+ e.g. `mde doc1 block1` will execute the block named `block1` in file `doc1`.
71
+
72
+ ### Changed
73
+
74
+ - Naming saved script files: The file name contains the time stamp, document name, and block name.
75
+ - Renamed folder with fixtures.
76
+ - Command options:
77
+
78
+ | YAML Name | Environment Variable | Option Name | Default | Purpose |
79
+ | :--- | :--- | :--- | :--- | :--- |
80
+ | debug | MDE_DEBUG | `--debug` | False | Output debugging information (verbose) |
81
+ | filename | MDE_FILENAME | `--filename` | `README.md`* | File name of document |
82
+ | output_execution_summary | MDE_OUTPUT_STDOUT_SUMMARY | `--output-execution-summary` | False | Display summary for execution |
83
+ | output_script | MDE_OUTPUT_SCRIPT | `--output-script` | False | Display script |
84
+ | output_stdout | MDE_OUTPUT_EXECUTION | `--output-stdout` | True | Display standard output from execution |
85
+ | path | MDE_PATH | `--path` | `.` | Path to document(s) |
86
+ | save_executed_script | MDE_SAVE_EXECUTED_SCRIPT | `--save-executed-script` | False | Save executed script |
87
+ | saved_script_folder | MDE_SAVED_SCRIPT_FOLDER | `--saved-script-folder` | `logs` | Saved script folder |
88
+ | select_page_height | MDE_SELECT_PAGE_HEIGHT | | `12` | Menu page height (maximum) |
89
+ | user_must_approve | MDE_USER_MUST_APPROVE | `--user-must-approve` | True | Pause to approve execution |
90
+
91
+ - Configuration options:
92
+
93
+ | YAML Name | Environment Variable | Default |
94
+ | :--- | :--- | :--- |
95
+ | block_name_excluded_match | MDE_BLOCK_NAME_EXCLUDED_MATCH | `^\(.+\)$` |
96
+ | block_name_match | MDE_BLOCK_NAME_MATCH | `:(?<title>\S+)( \|$)` |
97
+ | block_required_scan | MDE_BLOCK_REQUIRED_SCAN | `\+\S+` |
98
+ | fenced_start_and_end_match | MDE_FENCED_START_AND_END_MATCH | ``^`{3,}`` |
99
+ | fenced_start_ex_match | MDE_FENCED_START_EX_MATCH | ``^`{3,}(?<shell>[^`\s]*) *(?<name>.*)$`` |
100
+ | heading1_match | MDE_HEADING1_MATCH | `^# *(?<name>[^#]*?) *$` |
101
+ | heading2_match | MDE_HEADING2_MATCH | `^## *(?<name>[^#]*?) *$` |
102
+ | heading3_match | MDE_HEADING3_MATCH | `^### *(?<name>.+?) *$` |
103
+ | md_filename_glob | MDE_MD_FILENAME_GLOB | `*.[Mm][Dd]` |
104
+ | md_filename_match | MDE_MD_FILENAME_MATCH | `.+\\.md` |
105
+
106
+ Most options can be configured in multiple ways. In order of use (earliest superceded by last):
107
+ 1. environment variables
108
+ 2. the configuration file `.mde.yml` in the current folder
109
+ 3. command line arguments
110
+
111
+ #### Representing boolean values
112
+
113
+ Boolean values for options are specified as strings and interpreted as:
114
+ | Value | Boolean |
115
+ | :---: | :---: |
116
+ | *empty string* | False |
117
+ | `0` | False |
118
+ | `1` | True |
119
+ | *anything else* | True |
120
+
121
+ E.g. `opt1=1` will set option `opt1` to True.
122
+
123
+ Boolean options configured with environment variables:
124
+ - Set to `1` or non-empty value to save executed scripts; empty or `0` to disable saving.
125
+ e.g. `export MDE_SAVE_EXECUTED_SCRIPT=1`
126
+ e.g. `export MDE_SAVE_EXECUTED_SCRIPT=`
127
+ - Specify variable on command line.
128
+ e.g. `MDE_SAVE_EXECUTED_SCRIPT=1 mde`
129
+
130
+ ## [0.2.2] - 2022-03-17
131
+
132
+ - Update documentation.
2
133
 
3
134
  ## [0.2.1] - 2022-03-12
4
135
 
data/Gemfile CHANGED
@@ -10,3 +10,5 @@ gem 'rake', '~> 13.0'
10
10
  gem 'minitest', '~> 5.0'
11
11
 
12
12
  gem 'rubocop', '~> 1.21'
13
+ gem 'rubocop-minitest', require: false
14
+ gem 'rubocop-rake', require: false
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- markdown_exec (0.1.1)
4
+ markdown_exec (0.2.5)
5
5
  open3 (~> 0.1.1)
6
6
  optparse (~> 0.1.1)
7
7
  tty-prompt (~> 0.23.1)
@@ -34,6 +34,10 @@ GEM
34
34
  unicode-display_width (>= 1.4.0, < 3.0)
35
35
  rubocop-ast (1.16.0)
36
36
  parser (>= 3.1.1.0)
37
+ rubocop-minitest (0.18.0)
38
+ rubocop (>= 0.90, < 2.0)
39
+ rubocop-rake (0.6.0)
40
+ rubocop (~> 1.0)
37
41
  ruby-progressbar (1.11.0)
38
42
  tty-color (0.6.0)
39
43
  tty-cursor (0.7.1)
@@ -57,6 +61,8 @@ DEPENDENCIES
57
61
  minitest (~> 5.0)
58
62
  rake (~> 13.0)
59
63
  rubocop (~> 1.21)
64
+ rubocop-minitest
65
+ rubocop-rake
60
66
 
61
67
  BUNDLED WITH
62
68
  2.2.32
data/README.md CHANGED
@@ -1,56 +1,146 @@
1
1
  # MarkdownExec
2
2
 
3
- This gem allows you to interactively select and run code blocks in markdown files.
3
+ Interactively select and execute fenced code blocks in markdown files. Build complex scripts by naming and requiring blocks. Log resulting scripts and output. Re-run scripts.
4
4
 
5
- * Code blocks may be named.
5
+ * Code blocks may be named. Named blocks can be required by other blocks.
6
6
 
7
- * Named blocks can be required by other blocks.
7
+ * The user-selected code block, and all required blocks, are arranged into a script in the order they appear in the markdown file. The script can be presented for approval prior to execution.
8
8
 
9
- * The user-selected code block, and all required blocks, are arranged in the order they appear in the markdown file.
9
+ * Executed scripts can be saved. Saved scripts can be listed, selected, and executed.
10
10
 
11
- * The code is presented for approval prior to execution.
11
+ * Output from executed scripts can be saved.
12
+
13
+ ## Screenshots
14
+
15
+ ### Select a file
16
+
17
+ ![Select a file](/assets/select_a_file.png)
18
+
19
+ ### Select a block
20
+
21
+ ![Select a block](/assets/select_a_block.png)
22
+
23
+ ### Approve code
24
+
25
+ ![Approve code](/assets/approve_code.png)
26
+
27
+ ### Output
28
+
29
+ ![Output of execution](/assets/output_of_execution.png)
30
+
31
+ ### Example blocks
32
+
33
+ ![Example blocks](/assets/example_blocks.png)
12
34
 
13
35
  ## Installation
14
36
 
15
37
  Install:
16
-
17
38
  $ gem install markdown_exec
18
39
 
19
40
  ## Usage
20
41
 
21
- `mde --help`
42
+ ### Help
43
+
44
+ #### `mde --help`
45
+
22
46
  Displays help information.
23
47
 
24
- `mde`
48
+ ### Basic
49
+
50
+ #### `mde`
51
+
25
52
  Process `README.md` file in the current folder. Displays all the blocks in the file and allows you to select using [up], [down], and [return]. Press [ctrl]-c to abort selection.
26
53
 
27
- `mde -f my.md`
28
- `mde my.md`
54
+ #### `mde my.md` or `mde -f my.md`
55
+
29
56
  Select a block to execute from `my.md`.
30
57
 
31
- `mde -p .`
32
- `mde .`
58
+ #### `mde .` or `mde -p .`
59
+
33
60
  Select a markdown file in the current folder. Select a block to execute from that file.
34
61
 
35
- `mde --list-blocks`
62
+ ### Report documents and blocks
63
+
64
+ #### `mde --list-blocks`
65
+
36
66
  List all blocks in the all the markdown documents in the current folder.
37
67
 
38
- `mde --list-docs`
68
+ #### `mde --list-docs`
69
+
39
70
  List all markdown documents in the current folder.
40
71
 
72
+ ### Configuration
73
+
74
+ #### `mde --list-default-env` or `mde --list-default-yaml`
75
+
76
+ List default values that can be set in configuration file, environment, and command line.
77
+
78
+ #### `mde -0`
79
+
80
+ Show current configuation values that will be applied to the current run. Does not interrupt processing.
81
+
82
+ ### Save scripts
83
+
84
+ #### `mde --save-executed-script 1`
85
+
86
+ Save executed script in saved script folder.
87
+
88
+ #### `mde --list-recent-scripts`
89
+
90
+ List recent saved scripts in saved script folder.
91
+
92
+ #### `mde --select-recent-script`
93
+
94
+ Select and execute a recently saved script in saved script folder.
95
+
96
+ ### Save output
97
+
98
+ #### `mde --save-execution-output 1`
99
+
100
+ Save execution output in saved output folder.
101
+
41
102
  ## Behavior
103
+
42
104
  * If no file and no folder are specified, blocks within `./README.md` are presented.
43
105
  * If a file is specified, its blocks are presented.
44
106
  * If a folder is specified, its files are presented. When a file is selected, its blocks are presented.
45
107
 
46
108
  ## Configuration
47
109
 
48
- While starting up, reads the YAML configuration file `.mde.yml` in the current folder if it exists.
110
+ ### Environment Variables
49
111
 
50
- e.g. Use to set the default file for the current folder.
112
+ When executed, `mde` reads the current environment.
113
+ * Configuration in current and children shells, e.g. `export MDE_SAVE_EXECUTED_SCRIPT=1`.
114
+ * Configuration for the current command, e.g. `MDE_SAVE_EXECUTED_SCRIPT=1 mde`.
51
115
 
52
- * `filename: CHANGELOG.md` sets the file to open.
53
- * `folder: documents` sets the folder to search for default or specified files.
116
+ ### Configuration Files
117
+
118
+ * Configuration in all shells, e.g. environment variables set in your user's `~/.bashrc` or `~/.bash_profile` files.
119
+ * Configuration in the optional file `.mde.yml` in the current folder. .e.g. `save_executed_script: true`
120
+ * Configuration in a YAML file and read while parsing the inputs, e.g. `--config my_path/my_file.yml`
121
+
122
+ ### Program Arguments
123
+
124
+ * Configuration in command options, e.g. `mde --save-executed-script 1`
125
+
126
+ ## Representing boolean values
127
+
128
+ Boolean values expressed as strings are interpreted as:
129
+ | String | Boolean |
130
+ | :---: | :---: |
131
+ | *empty string* | False |
132
+ | `0` | False |
133
+ | `1` | True |
134
+ | *anything else* | True |
135
+
136
+ E.g. `opt1=1` will set option `opt1` to True.
137
+
138
+ Boolean options configured with environment variables:
139
+ - Set to `1` or non-empty value to save executed scripts; empty or `0` to disable saving.
140
+ e.g. `export MDE_SAVE_EXECUTED_SCRIPT=1`
141
+ e.g. `export MDE_SAVE_EXECUTED_SCRIPT=`
142
+ - Specify variable on command line.
143
+ e.g. `MDE_SAVE_EXECUTED_SCRIPT=1 mde`
54
144
 
55
145
  # Example blocks
56
146
 
@@ -76,20 +166,16 @@ export ACTIVITY=asleep
76
166
  echo "$TIME -> $ACTIVITY"
77
167
  ```
78
168
 
79
- ## Example blocks
80
- ![Sample blocks](/assets/blocks.png)
81
-
82
- ## Selecting a file
83
- ![Selecting a file](/assets/select_file.png)
84
-
85
- ## Selecting a block
86
- ![Selecting a block](/assets/select.png)
87
-
88
- ## Approving code
89
- ![Approving code](/assets/approve.png)
169
+ ``` :missing_command
170
+ fail
171
+ ```
90
172
 
91
- ## Output
92
- ![Output of execution](/assets/executed.png)
173
+ ``` :exit_value
174
+ echo "a"
175
+ echo "b"
176
+ echo "c" >>/dev/stderr
177
+ grep nx Gemfile
178
+ ```
93
179
 
94
180
  # License
95
181
 
data/Rakefile CHANGED
@@ -3,38 +3,50 @@
3
3
  require 'bundler/gem_tasks'
4
4
  require 'rake/testtask'
5
5
 
6
- Rake::TestTask.new(:test) do |t|
7
- t.libs << 'test'
8
- t.libs << 'lib'
9
- t.test_files = FileList['test/**/*_test.rb']
6
+ Rake::TestTask.new(:test) do |task|
7
+ task.libs << 'test'
8
+ task.libs << 'lib'
9
+ task.test_files = FileList['test/**/*_test.rb']
10
10
  end
11
11
 
12
12
  require 'rubocop/rake_task'
13
13
 
14
- RuboCop::RakeTask.new
14
+ RuboCop::RakeTask.new do |task|
15
+ # task.requires << 'rubocop-minitest'
16
+ end
17
+
18
+ desc 'named task because minitest not included in rubocop tests'
19
+ task :rubocopminitest do
20
+ `rubocop --require rubocop-minitest`
21
+ end
15
22
 
16
23
  require_relative 'lib/markdown_exec/version'
17
24
 
18
- task default: %i[test rubocop]
25
+ task default: %i[test rubocop rubocopminitest]
19
26
 
20
27
  # task :default => :build
21
28
 
29
+ desc 'gem build'
22
30
  task :build do
23
31
  system "gem build #{MarkdownExec::GEM_NAME}.gemspec"
24
32
  end
25
33
 
34
+ desc 'gem install'
26
35
  task install: :build do
27
36
  system "gem install #{MarkdownExec::GEM_NAME}-#{MarkdownExec::VERSION}.gem"
28
37
  end
29
38
 
39
+ desc 'gem publish'
30
40
  task publish: :build do
31
41
  system "gem push #{MarkdownExec::GEM_NAME}-#{MarkdownExec::VERSION}.gem"
32
42
  end
33
43
 
44
+ desc 'gem uninstall'
34
45
  task uninstall: :build do
35
46
  system "gem uninstall #{MarkdownExec::GEM_NAME}"
36
47
  end
37
48
 
49
+ desc 'gem build clean'
38
50
  task :clean do
39
51
  system 'rm *.gem'
40
52
  end
Binary file
Binary file
Binary file
Binary file
Binary file
data/fixtures/bash1.md ADDED
@@ -0,0 +1,12 @@
1
+ ``` :one
2
+ a
3
+ ```
4
+ ```bash :two +one
5
+ b
6
+ ```
7
+ ```bash :three +two +one
8
+ c
9
+ ```
10
+ ```bash :four +three
11
+ d
12
+ ```
data/fixtures/bash2.md ADDED
@@ -0,0 +1,15 @@
1
+ ``` :one
2
+ a
3
+ ```
4
+ ``` :two +one
5
+ b
6
+ ```
7
+ ``` :three +two
8
+ c
9
+ ```
10
+ ``` :four
11
+ d
12
+ ```
13
+ ``` :five +four +one
14
+ e
15
+ ```
@@ -0,0 +1,6 @@
1
+ ``` :one
2
+ a
3
+ ```
4
+ ```expect
5
+ b
6
+ ```
@@ -0,0 +1,9 @@
1
+ ``` :one
2
+ a
3
+ ```
4
+ ``` :(two)
5
+ b
6
+ ```
7
+ ``` :three
8
+ c
9
+ ```
data/fixtures/exec1.md ADDED
@@ -0,0 +1,8 @@
1
+ ```bash ls
2
+ ls
3
+ ```
4
+
5
+ ```bash two-three
6
+ echo "TWO"
7
+ echo "THREE"
8
+ ```
@@ -0,0 +1,19 @@
1
+ ``` :one
2
+ a
3
+ ```
4
+ # h1
5
+ ``` :two
6
+ b
7
+ ```
8
+ ## h2
9
+ ``` :three
10
+ c
11
+ ```
12
+ ### h3
13
+ ``` :four
14
+ d
15
+ ```
16
+ ### h4
17
+ ``` :five
18
+ e
19
+ ```
@@ -0,0 +1,9 @@
1
+ #
2
+ ##
3
+ ``` one
4
+ a
5
+ ```
6
+
7
+ ```bash two
8
+ b
9
+ ```
@@ -0,0 +1,6 @@
1
+ ```
2
+ no name
3
+ ```
4
+ ``` :name1
5
+ with name
6
+ ```
@@ -2,7 +2,7 @@
2
2
 
3
3
  module MarkdownExec
4
4
  APP_NAME = 'MDE'
5
- APP_DESC = 'Markdown block executor'
5
+ APP_DESC = 'Markdown Executor'
6
6
  GEM_NAME = 'markdown_exec'
7
- VERSION = '0.2.1'
7
+ VERSION = '0.2.5'
8
8
  end