{"action":"created","issue":{"url":"https://api.github.com/repos/superfly/fly/issues/64","repository_url":"https://api.github.com/repos/superfly/fly","labels_url":"https://api.github.com/repos/superfly/fly/issues/64/labels{/name}","comments_url":"https://api.github.com/repos/superfly/fly/issues/64/comments","events_url":"https://api.github.com/repos/superfly/fly/issues/64/events","html_url":"https://github.com/superfly/fly/pull/64","id":312637410,"number":64,"title":"feat: parse all cli options and commands using a new parser script","user":{"login":"pudility","id":13806068,"avatar_url":"https://avatars1.githubusercontent.com/u/13806068?v=4","gravatar_id":"","url":"https://api.github.com/users/pudility","html_url":"https://github.com/pudility","followers_url":"https://api.github.com/users/pudility/followers","following_url":"https://api.github.com/users/pudility/following{/other_user}","gists_url":"https://api.github.com/users/pudility/gists{/gist_id}","starred_url":"https://api.github.com/users/pudility/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pudility/subscriptions","organizations_url":"https://api.github.com/users/pudility/orgs","repos_url":"https://api.github.com/users/pudility/repos","events_url":"https://api.github.com/users/pudility/events{/privacy}","received_events_url":"https://api.github.com/users/pudility/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":14,"created_at":"2018-04-09T18:27:36Z","updated_at":"2018-04-11T19:37:06Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/superfly/fly/pulls/64","html_url":"https://github.com/superfly/fly/pull/64","diff_url":"https://github.com/superfly/fly/pull/64.diff","patch_url":"https://github.com/superfly/fly/pull/64.patch"},"body":"This PR allows us to parse every option we receive. \r\n\r\n### Benefits\r\n - Allows options and commands to be in any order #58\r\n - Every option and command is tested\r\n - Every option and command work\r\n - Customizable if we need to change anything down the road\r\n\r\n### Usage\r\n```\r\n$ fly test --path foo\r\n$ fly --path foo test # this also works\r\n$ fly -p foo test # this also works\r\n\r\n# more examples\r\n$ fly --port 1234 server --uglify -i # start server on port 1234 enable both uglify and inspect\r\n$ fly secrets set foo\r\n$ fly secrets set --from-file foo\r\n```\r\n<details>\r\n<summary>Usage</summary>\r\n<br>\r\n\r\n```\r\n$ fly\r\nFly CLI\r\n\r\n\t Usage:  fly [command] [options]\r\n\r\n\t Options:\r\n\r\n\t - app (--app, -a): App to use for commands.\r\n\t - env (--env, -e): Environment to use for commands.\r\n\t - token (--token, -t): Fly Access Token (can be set via environment FLY_ACCESS_TOKEN)\r\n\t - from-file (--from-file, -f): Use a file's contents as the secret value.\r\n\t - path (--path, -p): Test from a specific path, defaults to {test,spec}/**/*.{test,spec}.js\r\n\t - port (--port, -p): Port to bind to\r\n\t - uglify (--uglify, -u): uglify your code like we'll use in production (warning: slow!)\r\n\t - inspect (--inspect, -i): use the v8 inspector on your fly app\r\n\r\n\t Commands:\r\n\r\n\t - version: The current version of Fly CLI\r\n\t - apps: Manage Fly apps.\r\n\t - create: Create a Fly app.\r\n\t - orgs: Manage Fly orgs.\r\n\t - deploy: Deploy your local Fly app.\r\n\t - releases: Manage Fly apps.\r\n\t - secrets: Manage your Fly app secrets.\r\n\t - set: Set a secret to use in your config.\r\n\t - test: Run unit tests, defaults to {test,spec}/**/*.{test,spec}.js\r\n\t - server: Run the local Fly development server\r\n\t - hostnames: Manage Fly app's hostnames.\r\n\t - add: Add a hostname to your fly app.\r\n\t - login: Login to Fly and save credentials locally.\r\n\t - fetch: Fetch your Fly app locally.\r\n\t - logs: Logs from your app.\r\n```\r\n\r\n</details>\r\n\r\n### COMMAND/OPTION object structure\r\n[snippet](https://github.com/pudility/fly/blob/flags/src/cmd/parser.ts#L22-L37)\r\n```JavaScript\r\n  /*\r\n  * add takes an array of options. Options are objects in this format:\r\n  * @property name [required] this is the name that can the user can type to get\r\n                           this option or command. for commands the user can use\r\n                           the name and for options the user can use either\r\n                           --the-name or -the first letter of the name eg. name:\r\n                           from-file will be triggered by: -f || --from-file\r\n  * @property type [required] the type of option. this can be either COMMAND or OPTION\r\n  * @property action [required (for commands)] the function to be run when a\r\n                                            command is given by the user.\r\n  * @property mapTo [optional] the name of the object returned from getOptions\r\n  * @property description [optional] description of the command or option\r\n  * @property usage [optional] the useage of a particular command or option\r\n  * @property takesArguments [optional] allows commands to take arguments\r\n  * @property bool [optional] makes the option not take any value\r\n  */\r\n```\r\n### Testing\r\n[Every command and option is tested to make sure that they work properly.](https://github.com/pudility/fly/blob/flags/test/command.spec.ts)"},"comment":{"url":"https://api.github.com/repos/superfly/fly/issues/comments/380571044","html_url":"https://github.com/superfly/fly/pull/64#issuecomment-380571044","issue_url":"https://api.github.com/repos/superfly/fly/issues/64","id":380571044,"user":{"login":"jeromegn","id":43325,"avatar_url":"https://avatars3.githubusercontent.com/u/43325?v=4","gravatar_id":"","url":"https://api.github.com/users/jeromegn","html_url":"https://github.com/jeromegn","followers_url":"https://api.github.com/users/jeromegn/followers","following_url":"https://api.github.com/users/jeromegn/following{/other_user}","gists_url":"https://api.github.com/users/jeromegn/gists{/gist_id}","starred_url":"https://api.github.com/users/jeromegn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeromegn/subscriptions","organizations_url":"https://api.github.com/users/jeromegn/orgs","repos_url":"https://api.github.com/users/jeromegn/repos","events_url":"https://api.github.com/users/jeromegn/events{/privacy}","received_events_url":"https://api.github.com/users/jeromegn/received_events","type":"User","site_admin":false},"created_at":"2018-04-11T19:37:06Z","updated_at":"2018-04-11T19:37:06Z","author_association":"CONTRIBUTOR","body":"> One of which being that commands must be in a specific order, another being that some commands just don't work\r\n\r\nI think extending the command options like @mrkurt mentioned would solve that issue. if every subcommand options also accept the root options, then you can use `--app` and `--token` anywhere.\r\n\r\n> Another reason to use custom code is because we can test every scenario to make sure things like the issue above do not happen.\r\n\r\nYou can definitely test commandpost CLI commands. There are decent examples in the commandpost repo: https://github.com/vvakame/commandpost/blob/master/test/commandSpec.ts\r\n\r\nWe prefer using commandpost because it's already there and there's a smaller change in our code we can make to make it work like we want it to.\r\n\r\nWriting our own custom CLI parser is too much like reinventing the wheel. There are a lot of other parsers out there that would also work.\r\n\r\nThe main criteria for choosing the CLI package was that it allowed sub commands in a nice manner. We used to use commander.js, but it required us to create different files for all sub commands (à la git.)\r\n\r\ncommandpost also is all TypeScript and gives us \"some\" type safety with arguments and options. It's not perfect but it's pretty good.\r\n\r\nWe can also improve commandpost by fixing the issues we encounter upstream, in their repo.\r\n\r\nI think the smallest change here is to extend all subcommand options to include the global (root) options. One challenge with this approach is getting the app name from anywhere. Right now we just check the root command if it has the app option set, but we'd need to check all subcommands if we extend the options to accept `--app`.\r\n\r\nI'm sorry I didn't pick up on the fact that this was a big rewrite, I was under the impression you we're still using commandpost. My bad."}}
{"actor":{"display_login":"jeromegn"}}