ddev icon indicating copy to clipboard operation
ddev copied to clipboard

Idea: Support --- yaml frontmatter in custom commands for Annotations

Open LionsAd opened this issue 5 years ago • 7 comments

Just an idea that I had while parsing the custom commands docs.

It would be nicer to write:

#!/usr/bin/env bash

## Frontmatter
<<'---'
description: 'Run MySQLWorkbench against current db'
usage: mysqlworkbench
example: 'ddev mysqlworkbench'
flags:
  flag:
    usage: 'sets the flag option'
---

echo "Hello"

The : <<'---' is a trick to redirect the output to an empty command.

The following is also possible:

#!/usr/bin/env bash

## Frontmatter
<<---
description: 'Run MySQLWorkbench against current db'
usage: mysqlworkbench
example: 'ddev mysqlworkbench'
flags:
  flag:
    usage: 'sets the flag option'
---

echo "Hello"

But if the standard delimiters are not needed it could also be:

#!/usr/bin/env bash

## Frontmatter
: <<YAML_MATTER
description: 'Run MySQLWorkbench against current db'
usage: mysqlworkbench
example: 'ddev mysqlworkbench'
flags:
  flag:
    usage: 'sets the flag option'
YAML_MATTER

echo "Hello"

Edit, seems the preferred way is:

#!/usr/bin/env bash

<<'###FRONTMATTER'
description: 'Run MySQLWorkbench against current db'
usage: mysqlworkbench
example: 'ddev mysqlworkbench'
flags:
  flag:
    usage: 'sets the flag option'
###FRONTMATTER

echo "Hello"

Edit 2: One more variation that's parseable with a standard frontmatter parser (if garbage before is ignored):

#!/usr/bin/env bash

<<'###COMMENT'
---
description: 'Run MySQLWorkbench against current db'
usage: mysqlworkbench
example: 'ddev mysqlworkbench'
flags:
  flag:
    usage: 'sets the flag option'
---
###COMMENT

echo "Hello"

LionsAd avatar Nov 13 '20 12:11 LionsAd

This was actually in your plans, right @gilbertsoft ?

rfay avatar Nov 13 '20 12:11 rfay

Yes, working already on this. Will go into https://github.com/drud/ddev/pull/2519

gilbertsoft avatar Nov 13 '20 12:11 gilbertsoft

Oh nice! 👍

LionsAd avatar Nov 13 '20 12:11 LionsAd

Will also provide an updater which will change all your custom commands to the new format on the fly. I guess this will be a great improvement for the custom commands.

gilbertsoft avatar Nov 13 '20 12:11 gilbertsoft

Well, it might give you some ideas for a proper prelude in any case :)

LionsAd avatar Nov 13 '20 13:11 LionsAd

Unfortunately, #2519 never reached maturity :(

rfay avatar Oct 27 '23 16:10 rfay