ulrikstrid / reenv

dotenv-cli implementation in native ReasonML providing near-instant startup times
MIT License
65 stars 3 forks source link

Getting 'required argument ARGS is missing' error #9

Closed yawaramin closed 5 years ago

yawaramin commented 5 years ago

Here is the error:

$ reenv ls
/usr/local/lib/node_modules/reenv/3/i/reenv-abbc298e/bin/reenv: required
                                                                argument ARGS
                                                                is missing
Usage: /usr/local/lib/node_modules/reenv/3/i/reenv-abbc298e/bin/reenv [OPTION]... CMD ARGS
Try `/usr/local/lib/node_modules/reenv/3/i/reenv-abbc298e/bin/reenv --help' for more information.

Version is 0.2.0.

(dotenv ls works. reenv ls subdir also works for a given subdir.)

ulrikstrid commented 5 years ago

I goofed and it expects at least 2 args, fixing that today.

yawaramin commented 5 years ago

Here's a sample usage of the OCaml built-in Arg module:

// Main.re

let prepend(item, listRef) = listRef := [item, ...listRef^];
let addEnvFile(envFiles) = Arg.String(envFile => prepend(envFile, envFiles));

// Need 'rest args' to stop parsing the command line
let addRestArg(restArgs) = Arg.Rest(arg => prepend(arg, restArgs));

let specList(envFiles, restArgs) = [
  ("-e", addEnvFile(envFiles), "FILE Load environment variables from FILE"),
  ("--", addRestArg(restArgs), "[COMMAND [ARGS]] Command to run"),
];

let usage = {|NAME
  reenv - load environment variables and execute command

SYNOPSIS
  reenv [-e FILE] [-help] [--help] [-- COMMAND [ARGS]]

OPTIONS|};

let () = {
  let envFiles = ref([]);
  let restArgs = ref([]);

  Arg.parse(specList(envFiles, restArgs), ignore, usage);
  // Load env vars from envFiles ... then run command:
  restArgs^ |> List.rev |> String.concat(" ") |> Sys.command |> ignore;
};

Output looks like this:

$ esy x Hello.exe -h
/Users/yawar/src/hello-reason/_esy/default/store/i/hello_reason-f08a77ce/bin/Hello.exe: unknown option '-h'.
NAME
  reenv - load environment variables and execute command

SYNOPSIS
  reenv [-e FILE] [-help] [--help] [-- COMMAND [ARGS]]

OPTIONS
  -e FILE Load environment variables from FILE
  -- [COMMAND [ARGS]] Command to run
  -help  Display this list of options
  --help  Display this list of options
ulrikstrid commented 5 years ago

Thanks for the suggestion on Arg, I ended up using Cmdliner anyway as I wanted to learn that API.

The issue should be fixed in 0.2.1 that I just tagged. Closing tomorrow if this works.

yawaramin commented 5 years ago

Gotcha. Yeah that makes sense. Looking forward to trying it out!