Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Refactored th1 argv_xxx to (argv xxx). Added th1_argv.wiki doc. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | th1-query-api |
Files: | files | file ages | folders |
SHA1: |
615ee71798931eec18ef34a64b3ac2c0 |
User & Date: | stephan 2012-07-14 21:13:24.678 |
Context
2012-07-14
| ||
21:36 | Fixed short-form flag handling for th1 argv command in CLI mode. It now handles GET/POST params. ... (check-in: 413a33f2 user: stephan tags: th1-query-api) | |
21:13 | Refactored th1 argv_xxx to (argv xxx). Added th1_argv.wiki doc. ... (check-in: 615ee717 user: stephan tags: th1-query-api) | |
20:59 | Refactored th1 query API col_xxx and bind_xxx to (col xxx) and (bind xxx). ... (check-in: 8260fdc9 user: stephan tags: th1-query-api) | |
Changes
Changes to src/th_main.c.
︙ | ︙ | |||
722 723 724 725 726 727 728 729 | return TH_ERROR; } } Th_ToInt(interp, zVal, strlen(zVal), &val); Th_SetResultInt( interp, val ); return TH_OK; } | > | > > > > > | | | | | | > > > > > > > > | 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 | return TH_ERROR; } } Th_ToInt(interp, zVal, strlen(zVal), &val); Th_SetResultInt( interp, val ); return TH_OK; } static int argvTopLevelCmd( Th_Interp *interp, void *ctx, int argc, const char **argv, int *argl ){ static Th_SubCommand aSub[] = { {"len", argvArgcCmd}, {"at", argvGetAtCmd}, {"getstr", argvFindOptionStringCmd}, {"getbool", argvFindOptionBoolCmd}, {"getint", argvFindOptionIntCmd}, {0, 0} }; Th_CallSubCommand2( interp, ctx, argc, argv, argl, aSub ); } int th_register_argv(Th_Interp *interp){ static Th_Command_Reg aCommand[] = { {"argv", argvTopLevelCmd, 0 }, {0, 0, 0} }; Th_register_commands( interp, aCommand ); } #endif /* end TH_USE_ARGV */ |
︙ | ︙ |
Changes to test/th1-query-api-1.th1.
︙ | ︙ | |||
111 112 113 114 115 116 117 | #set consts $SQLITE_CONSTANTS puts consts = $consts "\n" for {set i 0} {$i < [llength $consts]} {incr i} { set x [lindex $consts $i] puts \$$x = [expr \$$x] "\n" } | | | | | | | | | 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | #set consts $SQLITE_CONSTANTS puts consts = $consts "\n" for {set i 0} {$i < [llength $consts]} {incr i} { set x [lindex $consts $i] puts \$$x = [expr \$$x] "\n" } set ARGC [argv len] puts ARGC = $ARGC "\n" for {set i 0} {$i < $ARGC} {incr i} { puts "argv at $i = " [argv at $i] \n } set magicDefault hi set optA [argv getstr AA a $magicDefault] puts "argv getstr AA = " $optA \n set optA [argv getbool BB b 0] puts "argv getbool BB = " $optA \n set exception 0 catch { argv getint noSuchOptionAndNoDefault } exception puts exception = $exception "\n" enable_output 1 proc multiStmt {} { set max 5 |
︙ | ︙ |
Added www/th1_argv.wiki.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | <h1>TH1 "argv" API</h1> The "argv" API provides features for accessing command-line arguments and GET/POST values. Example usage: <nowiki><pre> <th1> set argc [argv len] set appName [argv at 0] # Fetch --foo|-f argument: set foo [argv getstr foo f "default value"] <th1> </pre></nowiki> The various subcommands are described below... <h2>len</h2> Returns the number of arguments. <nowiki><pre> set argc [argv len] </pre></nowiki> <h2>at</h2> Fetches the argument at the given index. <nowiki><pre> set arg [argv at 3] </pre></nowiki> <h2>getstr</h2> Searches for a CLI/GET/POST parameter. This function has some non-intuitive behaviour inherited from fossil's internals: once a flag/parameter is fetched, it is removed from the internal arguments list, meaning that this function will never see it a second time. <nowiki><pre> set something [argv getstr "something" "S" "default"] </pre></nowiki> If no default value is provided, an error is triggered if the value is not found. <h2>getbool</h2> Works almost like <tt>getstr</tt> but searches for boolean flags. CLI boolean flags have no explicit value, and are "true" if the are set at all. <nowiki><pre> set doSomething [argv getbool "do-something" "D" 0] </pre></nowiki> <h2>getint</h2> Works almost like <tt>getstr</tt> but searches for integer flags. <nowiki><pre> set limit [argv getbool "limit" "L" 10] </pre></nowiki> |