{"action":"opened","issue":{"url":"https://api.github.com/repos/accre/lstore-lio/issues/11","labels_url":"https://api.github.com/repos/accre/lstore-lio/issues/11/labels{/name}","comments_url":"https://api.github.com/repos/accre/lstore-lio/issues/11/comments","events_url":"https://api.github.com/repos/accre/lstore-lio/issues/11/events","html_url":"https://github.com/accre/lstore-lio/issues/11","id":113409684,"number":11,"title":"Change command line/config parsing.","user":{"login":"PerilousApricot","id":93354,"avatar_url":"https://avatars.githubusercontent.com/u/93354?v=3","gravatar_id":"","url":"https://api.github.com/users/PerilousApricot","html_url":"https://github.com/PerilousApricot","followers_url":"https://api.github.com/users/PerilousApricot/followers","following_url":"https://api.github.com/users/PerilousApricot/following{/other_user}","gists_url":"https://api.github.com/users/PerilousApricot/gists{/gist_id}","starred_url":"https://api.github.com/users/PerilousApricot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PerilousApricot/subscriptions","organizations_url":"https://api.github.com/users/PerilousApricot/orgs","repos_url":"https://api.github.com/users/PerilousApricot/repos","events_url":"https://api.github.com/users/PerilousApricot/events{/privacy}","received_events_url":"https://api.github.com/users/PerilousApricot/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-10-26T17:37:54Z","updated_at":"2015-10-26T17:37:54Z","closed_at":null,"body":"I see two things that are slightly coupled that could be done to keep weird arguments/configs from causing the command line tool from segfaulting.\r\n\r\n* Move command line parsing to getopt\r\n* Rejigger ini parsing\r\n\r\nInstead of the (somewhat) ad-hoc way we bring up configurations https://github.com/accre/lstore-lio/blob/master/lio_config.c#L818 and load arguments https://github.com/accre/lstore-lio/blob/master/lio_config.c#L1159 and write the \"usage\" help message https://github.com/accre/lstore-lio/blob/master/lio_config.c#L699 , I want to unify them in a way that will both help us auto-document all the different parameters, add some type safety, and bake in the defaults into one place.\r\n\r\nI see something like the following:\r\n\r\n```c\r\ntypedef enum { ARG_INT, ARG_UINT, ARG_SECTION, /* other types */ } lio_arg_desc_type_enum;\r\ntypedef union { int i, uint ui,  /* other types */ } lio_arg_desc_type_union;\r\ntypedef struct {\r\n    const char * name;\r\n    const char * description;\r\n    lio_arg_desc_type_enum type;\r\n    lio_arg_desc_type_union default;\r\n} lio_arg_desc_t;\r\n\r\n#define INT_VALUE(n,d,z) { .name = n, .description = d, .type = ARG_INT, .default.i = z }\r\n/* similar defines for other types */\r\n\r\nconst lio_arg_desc_t inner_desc[] = {\r\n    INT_VALUE(\"bar\", \"How many bars should we have\", 1)\r\n}\r\nconst lio_arg_desc_t top_desc[] = {\r\n    INT_VALUE(\"foo\", \"How many foos should we have\", 0),\r\n    INT_VALUE(\"probs\", \"Number of problems\", 99),\r\n    SECTION_VALUE(\"inner\", \"Stores information about bars\", inner_desc),\r\n}\r\n```\r\n\r\nThe same machinery can be used for command line arguments, which will chuck out an inip with the input values instead of a bunch of variables.\r\n\r\nIn both cases, we can then do an introspection of variables passed in and alert the user early that they're giving us something wrong. I constantly pass the wrong things in and get a segfault, which isn't user friendly. If we know early enough, we can panic sensibly. We also describe fully from a single canonical source the arguments expected/allowed. This will let us also let us spit out things like, \"What does a default configuration look like\" automagically.\r\n\r\nOnce those two are using the \"same\" machinery, we can then enable things like having \"-o inner.bar=99\" on the command line, which override values in the configuration. Or perhaps letting environment variables set values as well.\r\n    \r\n"}}