From 916e227028ab19e58a4ae1e5ebb1fa38691633bd Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Thu, 23 Nov 2017 16:09:14 -0500 Subject: 0.20.1 struct for opt_actions --- org/sdp.org | 200 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 180 insertions(+), 20 deletions(-) (limited to 'org/sdp.org') diff --git a/org/sdp.org b/org/sdp.org index af7fe98..a6e552f 100644 --- a/org/sdp.org +++ b/org/sdp.org @@ -26,7 +26,7 @@ struct Version { int minor; int patch; } -enum ver = Version(0, 20, 0); +enum ver = Version(0, 20, 1); #+END_SRC #+NAME: version_txt @@ -230,6 +230,8 @@ look into using getopt [[http://dlang.org/phobos/std_getopt.html][getopt]] [[http://dlang.org/library/std/getopt.html][getopt]] +***** getopt + #+NAME: sdp_args #+BEGIN_SRC d bool[string] opts = [ @@ -319,6 +321,169 @@ auto helpInfo = getopt(args, if (helpInfo.helpWanted) { defaultGetoptPrinter("Some information about the program.", helpInfo.options); } +#+END_SRC + +***** getopt hash to struct + +#+NAME: sdp_args +#+BEGIN_SRC d +struct OptActions { + auto assertions() { + auto _k = opts["assertions"]; + return _k; + } + auto concordance() { + auto _k = opts["concordance"]; + return _k; + } + auto debug_do() { + auto _k = opts["debug"]; + return _k; + } + auto digest() { + auto _k = opts["digest"]; + return _k; + } + auto docbook() { + auto _k = opts["docbook"]; + return _k; + } + auto epub() { + auto _k = opts["epub"]; + return _k; + } + auto html() { + auto _k = opts["html"]; + return _k; + } + auto html_seg() { + auto _k = opts["html-seg"]; + return _k; + } + auto html_scroll() { + auto _k = opts["html-scroll"]; + return _k; + } + auto manifest() { + auto _k = opts["manifest"]; + return _k; + } + auto ocn() { + auto _k = opts["ocn"]; + return _k; + } + auto odt() { + auto _k = opts["odt"]; + return _k; + } + auto pdf() { + auto _k = opts["pdf"]; + return _k; + } + auto postgresql() { + auto _k = opts["postgresql"]; + return _k; + } + auto qrcode() { + auto _k = opts["qrcode"]; + return _k; + } + auto sisupod() { + auto _k = opts["sisupod"]; + return _k; + } + auto source() { + auto _k = opts["source"]; + return _k; + } + auto sqlite_discrete() { + auto _k = opts["sqlite-discrete"]; + return _k; + } + auto sqlite_update() { + auto _k = opts["sqlite-update"]; + return _k; + } + auto sqlite_create() { + auto _k = opts["sqlite-create"]; + return _k; + } + auto sqlite_drop() { + auto _k = opts["sqlite-drop"]; + return _k; + } + auto text() { + auto _k = opts["text"]; + return _k; + } + auto verbose() { + auto _k = opts["verbose"]; + return _k; + } + auto xhtml() { + auto _k = opts["xhtml"]; + return _k; + } + auto xml_dom() { + auto _k = opts["xml-dom"]; + return _k; + } + auto xml_sax() { + auto _k = opts["xml-sax"]; + return _k; + } + auto section_toc() { + auto _k = opts["section_toc"]; + return _k; + } + auto section_body() { + auto _k = opts["section_body"]; + return _k; + } + auto section_endnotes() { + auto _k = opts["section_endnotes"]; + return _k; + } + auto section_glossary() { + auto _k = opts["section_glossary"]; + return _k; + } + auto section_biblio() { + auto _k = opts["section_biblio"]; + return _k; + } + auto section_bookindex() { + auto _k = opts["section_bookindex"]; + return _k; + } + auto section_blurb() { + auto _k = opts["section_blurb"]; + return _k; + } + auto backmatter() { + auto _k = opts["backmatter"]; + return _k; + } + auto skip_output() { + auto _k = opts["skip-output"]; + return _k; + } + auto languages_set() { + auto _k = settings["lang"].split(","); + return _k; + } + auto output_dir_set() { + auto _k = settings["output-dir"]; + return _k; + } +} +auto _opt_action = OptActions(); +#+END_SRC + +***** getopt processing path + +#+NAME: sdp_args +#+BEGIN_SRC d foreach(arg; args[1..$]) { if (arg.match(rgx.flag_action)) { flag_action ~= " " ~ arg; // flags not taken by getopt @@ -354,8 +519,8 @@ foreach(arg; args[1..$]) { contents_location ~ "ยป" ); auto contents_location_pth_ = (contents_location).to!string; - auto lang_rgx_ = regex(r"/(" ~ settings["lang"].split(",").join("|") ~ ")/"); - if (settings["lang"] == "all" + auto lang_rgx_ = regex(r"/(" ~ _opt_action.languages_set.join("|") ~ ")/"); + if (_opt_action.languages_set[0] == "all" || (contents_location_pth_).match(lang_rgx_) ) { fns_src ~= (((tmp_dir_).chainPath(contents_location_pth_)).array).to!(char[]); @@ -391,8 +556,8 @@ auto conf_files_composite_make = confFilesSDLtoStruct!()(sdl_root_config_share, ** 2a. actions independed of processing files #+NAME: sdp_do_selected #+BEGIN_SRC d -if (!(opts["skip-output"])) { - outputHubOp!()(opts); +if (!(_opt_action.skip_output)) { + outputHubOp!()(_opt_action); } #+END_SRC @@ -434,7 +599,7 @@ enforce( #+NAME: sdp_abstraction #+BEGIN_SRC d -auto t = SiSUabstraction!()(fn_src, opts, settings, env); +auto t = SiSUabstraction!()(fn_src, _opt_action, env); static assert(!isTypeTuple!(t)); static assert(t.length==2); auto doc_abstraction = t[dAM.abstraction]; @@ -447,7 +612,7 @@ auto doc_matters = t[dAM.matters]; #+NAME: sdp_each_file_do_debugs_checkdoc #+BEGIN_SRC d /+ โ†“ debugs +/ -if (doc_matters.opt_action["verbose"]) { +if (doc_matters.opt_action.verbose) { SiSUabstractionSummary!()(doc_abstraction, doc_matters); } #+END_SRC @@ -458,8 +623,8 @@ if (doc_matters.opt_action["verbose"]) { #+NAME: sdp_each_file_do_debugs_checkdoc #+BEGIN_SRC d /+ โ†“ debugs +/ -if ((doc_matters.opt_action["debug"]) -|| (doc_matters.opt_action["verbose"]) +if ((doc_matters.opt_action.debug_do) +|| (doc_matters.opt_action.verbose) ) { SiSUdebugs!()(doc_abstraction, doc_matters); } @@ -471,7 +636,7 @@ if ((doc_matters.opt_action["debug"]) #+NAME: sdp_each_file_do_selected_output #+BEGIN_SRC d /+ โ†“ output hub +/ -if (!(opts["skip-output"])) { +if (!(doc_matters.opt_action.skip_output)) { outputHub!()(doc_abstraction, doc_matters); } #+END_SRC @@ -511,10 +676,9 @@ template SiSUabstraction() { enum makeMeta { make, meta } enum docAbst { doc_abstraction, section_keys, segnames, segnames_0_4, images } static auto rgx = Rgx(); - auto SiSUabstraction(Fn,O,S,E)( + auto SiSUabstraction(Fn,O,E)( Fn fn_src, - O opts, - S settings, + O _opt_action, E env, ){ <> @@ -612,7 +776,7 @@ debug(steps) { auto da = SiSUdocAbstraction!()( _header_body_inserts[headBody.body_content], _make_and_meta_struct, - opts + _opt_action, ); static assert(!isTypeTuple!(da)); static assert(da.length==5); @@ -664,11 +828,7 @@ struct DocumentMatters { return _k; } auto opt_action() { - bool[string] _k = opts; - return _k; - } - auto opt_settings() { - string[string] _k = settings; + auto _k = _opt_action; return _k; } auto environment() { @@ -712,7 +872,7 @@ template SiSUabstractionSummary() { <> mixin InternalMarkup; <> - if (doc_matters.opt_action["verbose"]) { + if (doc_matters.opt_action.verbose) { <> } } -- cgit v1.2.3