refactor!: everything #85
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Excuse the bold title, but here it is
New "Command" language
Overall the syntax is different, but is inspired and somewhat resembles the current one. The idea idea is to separate DSL from containers in parsing and in processing stages. The new mdsh
Command
consists of these parts:in_cmd
defines how and where to source data, it can be one of three:<
— read file as is. The filepath is sourced fromdata_line
, ifdata
is available, it is read per line for filenames and each file is concatenated to previos one.$
— command execution. If thedata_line
is available, then it is executed as shell command. If thedata
is available it is passed to the command as via stdin (Closes add syntax for using existing snippet as input #57). If onlydata
is available but notdata_line
, then thedata
is executed as shell script.data_line
anddata
. In practice this is useful only for env variables settingout_cmd
defines what to do with the data fromin_cmd
, it can be one of three:> lang
— produce code block withlang
(similarly to currentas lang
statements).>
— produce raw markdown output fenced by comment-tags!
— expand data to shell variableswith these 3 * 3 commands you get 9 combinations, for example:
> < include.md
— read file and produce raw markdown> py < script.py
— read script.py and produce code block with languagepy
> yml $ ./script.py foo $bar
— executescript.py foo $bar
in shell and produceyml
code block>$ ./gen-md.py
— executegen-md.py
and produce raw markdown! foo=$bar
— usefoo=$bar
as "raw data" and expand env variables that can be used in the next shell executions!< .env
— read.env
and eval shell vars!$ ./gen-vars.py
— execute gen-vars and treat output as the list of shell variable assignmentsSo it can do quite a lot of things and the underlying model is pretty simple, and even allows to do some useless things, like
> hello
— would produce an empty code block withhello
language.Containers
Commands can be put into containers, here's all of them:
inline code blocks:
langname
is skipped, parsing starts right fromout_cmd
,data
is absent. Must start from new line and end with newline.code blocks:
Source env vars:
Execute script and produce yaml block (you can even put shebang at the top and use other than bash scripting languages.
Run
data_line
as oneline command and pass code block to it via stdin, producing raw markdown.oneline comments, similar to inline code blocks but hidden:
<!-- >< LICENSE.md -->
— includes LICENSE.mdmultiline comment blocks, behaves similarly to code blocks, but
langname
is not neededlinks. These are slightly deviate from the rest of containers:
Key syntax design changes
as lang
constructions and move lang on the left so source code in code block can be properly highlighted>
$
!
with the same meaning but differently arranged, so aCommand
is a little pipeline of two stages now>
behavior in code blocks, it was quite useless it produced raw markdownKey code changes
nom
library, now parsing code is easier to read and maintain and it's possible to do recursive parsing, f.x. in this PR comment tag fences can be in other comment tag fences, i.e.anyhow
). It is currently a mixture ofio::Error
s,unrwap
s,panic
s,expect
and customdie
function.Write
andRead
that could potentially give some performance boost in some casesmdsh
clobbers code block immediately following command substitution #29shellexpand
. It supports simple like${foo-def}
expressions, but not arbitrary code execution like$(date)
. I think for this real scripts ($
command) should be used if it is neededspec.{clear,processed}.md
)