mage icon indicating copy to clipboard operation
mage copied to clipboard

Better support for kebab-case targets

Open moorereason opened this issue 5 years ago • 7 comments

I haven't seen this discussed before, so I wanted to open a discussion.

In my experience, most Makefiles that are not just cramming words together (e.g. installhtml, installps) use kebab-cased targets (e.g. install-html, install-ps) instead of camelCased targets (e.g. installHtml, installPs). It would be helpful in migrating existing Makefiles and teams to mage if mage could more easily accommodate this pattern.

I'm aware that aliases can help here, but mage Help output only shows the primary targets after running them through the lowerFirst template func.

Two ideas:

  1. Add an option to show an alias (if one exists) instead of the primary, lowerFirst target in the Help output. The user could just setup kebab-cased aliases for multi-word targets and the Help output would play along.
  2. Add an option to use kebab-casing by default instead of lowerFirst. This would avoid the need for manual aliases from option 1.

moorereason avatar Jul 17 '20 18:07 moorereason

I like option 2 - give an option for kebab-cased targets. I think I would make this something you'd set in the magefile itself, like

const UseKebabTargets = true

that way it's standardized for everyone that uses that particular magefile, rather then being an environment variable, which would change behavior for each person (potentially screwing up other scripts and making each person have incompatible commands).

natefinch avatar Dec 23 '20 14:12 natefinch

I was favoring option 2 as well.

moorereason avatar Dec 23 '20 15:12 moorereason

Woul n't it be easier to allow the currently implemented namespaced targets to be called using a - as well as using a : ? Then this problem would be solved more elegantly.

beoran avatar Mar 16 '21 07:03 beoran

I going to give it a try.

jespino avatar Aug 05 '22 13:08 jespino

Quick question: can't we support alias by default? like if we pass my-target it first tries to run myTarget and if not it fails? You can't declare func my-target() error {...} in go so it makes sense, frictionless and retrocompatible to introduce aliasing? I can come up with a PR cc @anuraaga

jcchavezs avatar Sep 05 '22 07:09 jcchavezs

I like @jcchavezs's idea of falling back to to non-kebab if it was passed in as it seems like it'd generally help without hurting.

Another idea is to recognize //export comment on the function, this is the standard Go idiom for naming a function for use in an external system, often a C or WebAssembly library but magefile handling it would be quite natural too I think.

anuraaga avatar Sep 05 '22 07:09 anuraaga

I came up with a PR for this https://github.com/magefile/mage/pull/441

jcchavezs avatar Sep 15 '22 21:09 jcchavezs