magefile / mage

a Make/rake-like dev tool using Go
https://magefile.org
Apache License 2.0
4.14k stars 257 forks source link

Better support for kebab-case targets #311

Open moorereason opened 4 years ago

moorereason commented 4 years ago

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.
natefinch commented 3 years ago

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).

moorereason commented 3 years ago

I was favoring option 2 as well.

beoran commented 3 years ago

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.

jespino commented 2 years ago

I going to give it a try.

jcchavezs commented 2 years ago

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

anuraaga commented 2 years ago

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.

jcchavezs commented 2 years ago

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