{"action":"created","issue":{"url":"https://api.github.com/repos/amireh/lua_cliargs/issues/40","labels_url":"https://api.github.com/repos/amireh/lua_cliargs/issues/40/labels{/name}","comments_url":"https://api.github.com/repos/amireh/lua_cliargs/issues/40/comments","events_url":"https://api.github.com/repos/amireh/lua_cliargs/issues/40/events","html_url":"https://github.com/amireh/lua_cliargs/pull/40","id":58707295,"number":40,"title":"Add callbacks for arugument parsing","user":{"login":"o-lim","id":10095424,"avatar_url":"https://avatars.githubusercontent.com/u/10095424?v=3","gravatar_id":"","url":"https://api.github.com/users/o-lim","html_url":"https://github.com/o-lim","followers_url":"https://api.github.com/users/o-lim/followers","following_url":"https://api.github.com/users/o-lim/following{/other_user}","gists_url":"https://api.github.com/users/o-lim/gists{/gist_id}","starred_url":"https://api.github.com/users/o-lim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/o-lim/subscriptions","organizations_url":"https://api.github.com/users/o-lim/orgs","repos_url":"https://api.github.com/users/o-lim/repos","events_url":"https://api.github.com/users/o-lim/events{/privacy}","received_events_url":"https://api.github.com/users/o-lim/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-02-24T08:25:15Z","updated_at":"2015-02-26T19:22:36Z","closed_at":"2015-02-26T19:21:08Z","pull_request":{"url":"https://api.github.com/repos/amireh/lua_cliargs/pulls/40","html_url":"https://github.com/amireh/lua_cliargs/pull/40","diff_url":"https://github.com/amireh/lua_cliargs/pull/40.diff","patch_url":"https://github.com/amireh/lua_cliargs/pull/40.patch"},"body":"This allows the user to specify a function to be called whenever an argument is parsed. Just pass a callback function to `cli:add_arg` or `cli:optarg`, and that function will be called when the parser successfully parses the argument.\r\n\r\nArguments to the callback function are:\r\n* The argument key specified in `cli:add_arg` or `cli:optarg`\r\n* The value being assigned to the argument\r\n\r\nArgument callbacks can be used like so:\r\n```lua\r\nlocal function verifyEven(key, value)\r\n  if (tonumber(value) % 2) ~= 0 then\r\n    return nil, value .. \" is not an even\"\r\n  end\r\nend\r\n\r\nlocal cli = require 'cliargs'\r\ncli:set_name('myapp')\r\ncli:add_arg('EVEN', 'must be an even number',  verifyEven)\r\n\r\nlocal args = cli:parse()\r\nif not args then\r\n  os.exit(1)\r\nend\r\n\r\nprint('args.EVEN: ' .. args.EVEN)\r\n```\r\n```\r\n$ lua myapp.lua 14\r\nargs.EVEN:   14\r\n```\r\n```\r\n$ lua myapp.lua 15\r\nmyapp: error: 15 is not even; re-run with --help for usage\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/amireh/lua_cliargs/issues/comments/76248189","html_url":"https://github.com/amireh/lua_cliargs/pull/40#issuecomment-76248189","issue_url":"https://api.github.com/repos/amireh/lua_cliargs/issues/40","id":76248189,"user":{"login":"amireh","id":153786,"avatar_url":"https://avatars.githubusercontent.com/u/153786?v=3","gravatar_id":"","url":"https://api.github.com/users/amireh","html_url":"https://github.com/amireh","followers_url":"https://api.github.com/users/amireh/followers","following_url":"https://api.github.com/users/amireh/following{/other_user}","gists_url":"https://api.github.com/users/amireh/gists{/gist_id}","starred_url":"https://api.github.com/users/amireh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amireh/subscriptions","organizations_url":"https://api.github.com/users/amireh/orgs","repos_url":"https://api.github.com/users/amireh/repos","events_url":"https://api.github.com/users/amireh/events{/privacy}","received_events_url":"https://api.github.com/users/amireh/received_events","type":"User","site_admin":false},"created_at":"2015-02-26T19:22:36Z","updated_at":"2015-02-26T19:22:36Z","body":"It does make for a convenient API, and I guess we already trapped ourselves into this when we allowed it for options :)\r\n\r\nThanks for the work."}}