avh4 / elm-format

elm-format formats Elm source code according to a standard set of rules based on the official Elm Style Guide
BSD 3-Clause "New" or "Revised" License
1.31k stars 145 forks source link

Command line flag for version #425

Open andys8 opened 6 years ago

andys8 commented 6 years ago

Is it me or is there no -v or --version flag on the command line? I'd love to see it working in the expected way. I know it prints the version too, if there are no arguments.

> elm-format -v
Invalid option `-v'

elm-format-0.18 0.7.0-exp

    This version of elm-format contains features that may or may not appear in
    future releases. You can provide feedback about experimental features at
    https://goo.gl/forms/kLdTN1yikfOI8ZuA3

Usage: elm-format [INPUT] [--output FILE] [--yes] [--validate] [--stdin]
                  [--elm-version VERSION] [--upgrade]
  Format Elm source files.

Available options:
  -h,--help                Show this help text
  --output FILE            Write output to FILE instead of overwriting the given
                           source file.
  --yes                    Reply 'yes' to all automated prompts.
  --validate               Check if files are formatted without changing them.
  --stdin                  Read from stdin, output to stdout.
  --elm-version VERSION    The Elm version of the source files being formatted.
                           Valid values: 0.16, 0.17, 0.18. Default: 0.18
  --upgrade                Upgrade older Elm files to Elm 0.18 syntax

Examples:
  elm-format Main.elm                     # formats Main.elm
  elm-format Main.elm --output Main2.elm  # formats Main.elm as Main2.elm
  elm-format src/                         # format all *.elm files in the src directory

Full guide to using elm-format at <https://github.com/avh4/elm-format>

This would be great:

> elm-format -v
elm-format-0.18 0.7.0-exp
kachkaev commented 5 years ago

Here's my current workaround for getting and caching elm-format version in JS:

const execa = require("execa");

let cachedElmFormatVersion;
function getElmFormatVersion() {
  if (!cachedElmFormatVersion) {
    // a cleaner way of getting elm-format version
    // will be possible when this issue is closed:
    // https://github.com/avh4/elm-format/issues/425
    const help = execa.sync("elm-format", ["--help"]).stdout;
    cachedElmFormatVersion = help.match(/elm-format ([^\n]+)/)[1];
  }
  return cachedElmFormatVersion;
}