# # # add_dir "tests/automate_set_option" # # add_file "tests/automate_set_option/__driver__.lua" # content [0c46ec7e36b0350e4b719f1531990e2f9b375ca8] # # patch "ChangeLog" # from [f12c0cde72700c436e19112c1d41b91e361293a6] # to [a69d8b332702338554dd3db4d10c10330c16be59] # # patch "automate.cc" # from [d84bcc2a3343891d6702ac80c8c00672aea6037b] # to [15c0a24271e27bd3c7592a471eab1ebf4a949077] # # patch "monotone.texi" # from [fafb2b73256c554045bdfce2097ba8dddb100adb] # to [a5245b9f4fd2968bb6f2cbfd6da4bcf651a6d4c4] # # patch "testsuite.lua" # from [81c8e4aea652fb82e6c5499a6ee9d9a5741da25b] # to [4e0dbb06b2feea0921ea5febec02e913db2bca07] # ============================================================ --- tests/automate_set_option/__driver__.lua 0c46ec7e36b0350e4b719f1531990e2f9b375ca8 +++ tests/automate_set_option/__driver__.lua 0c46ec7e36b0350e4b719f1531990e2f9b375ca8 @@ -0,0 +1,45 @@ + +mtn_setup() + +check({"cp", "test.db", "test2.db"}, 0, false, false) + +--no args +check(mtn("automate", "set_option"), 1, false, false) + +--one arg +check(mtn("automate", "set_option", "database"), 1, false, false) + +--proper args, change database +check(mtn("automate", "set_option", "database", "test2.db"), 0, true, false) +check(qgrep("test2.db", "stdout"), 0, false, false) + +--proper args, invalid database +check(mtn("automate", "set_option", "database", "test3.db"), 1, false, true) +check(qgrep("invalid db file", "stderr"), 0, false, false) + +--proper args, set branch +check(mtn("automate", "set_option", "branch", "automate.set_option"), 0, true, false) +check(qgrep("automate.set_option", "stdout")) +check(qgrep("automate.set_option", "_MTN/options")) + +check({"mkdir", "option_keydir"}, 0, false, false) + +--invalid keydir +check(mtn("automate", "set_option", "keydir", "keydir_not_here"), 1, false, true) +check(qgrep("keydir does not exist", "stderr")) + +--valid keydir +check(mtn("automate", "set_option", "keydir", "option_keydir"), 0, true, false) +check(qgrep("option_keydir", "stdout")) +check(qgrep("option_keydir", "_MTN/options")) + +--invalid key (this key shouldn't be in 'keydir', which is currently set. +check(mtn("automate", "set_option", "key", "address@hidden"), 1, false, true) +check(qgrep("invalid key;", "stderr")) + +--switch back to original keydir +check(mtn("automate", "set_option", "keydir", "keys"), 0, false, false) +--good key... +check(mtn("automate", "set_option", "key", "address@hidden"), 0, true, false) +check(qgrep("address@hidden", "stdout")) +check(qgrep("address@hidden", "_MTN/options")) ============================================================ --- ChangeLog f12c0cde72700c436e19112c1d41b91e361293a6 +++ ChangeLog a69d8b332702338554dd3db4d10c10330c16be59 @@ -1,4 +1,8 @@ 2006-12-21 Ben Walton + * automate.cc: added set_option. + * monotone.texi: documented 'automate set_option' + +2006-12-21 Ben Walton * cmd_ws_commit.cc (CMD_NO_WORKSPACE(export)): added this command, which exports a revision/branch from the db. * Aliased publish to export. ============================================================ --- automate.cc d84bcc2a3343891d6702ac80c8c00672aea6037b +++ automate.cc 15c0a24271e27bd3c7592a471eab1ebf4a949077 @@ -1480,6 +1480,76 @@ AUTOMATE(get_option, N_("OPTION"), optio N(false, F("'%s' is not a recognized workspace option") % opt); } +// Name: set_option +// Arguments: +// 2: an option name and the new value +// Added in: 3.1 +// Purpose: Set the value of the named option in _MTN/options +// +// Output format: A string; the new value of the option +// (to possibly be used for verification) +// +// Errors: +// on any error condition, stdout is empty, stderr contains the error +// message and exit status should be 1. +// +// Sample output (for 'mtn automate set_option branch net.venge.monotone: +// net.venge.monotone +// +AUTOMATE(set_option, N_("OPTION"), options::opts::none) +{ + N(args.size() == 2, + F("wrong argument count")); + + // this command requires a workspace to be run in + app.require_workspace(); + + utf8 database_option, branch_option, key_option, keydir_option; + utf8 blank(""), user_output; + app.work.get_ws_options(database_option, branch_option, + key_option, keydir_option); + + string opt = idx(args, 0)(); + string value = idx(args, 1)(); + + if (opt == "database") + { + system_path db_path(value); + N(file_exists(db_path), F("invalid db file")); + database_option = db_path.as_internal(); + user_output = database_option; + } + else if (opt == "branch") + { + branch_option = value; + user_output = branch_option; + } + else if (opt == "key") + { + system_path key(keydir_option() + "/" + value); + N(file_exists(key), + F("invalid key; doesn't exist in keydir '%s'") % keydir_option); + key_option = value; + user_output = key_option; + } + else if (opt == "keydir") + { + system_path kd_path(value); + N(path_exists(kd_path), F("keydir does not exist")); + keydir_option = kd_path.as_internal(); + user_output = keydir_option; + } + else + N(false, F("'%s' is not a recognized workspace option") % opt); + + //we may set a keydir that doesn't contain the previously set key + //since emptying key_option only serves to make set_ws_options use + //the previously existing value, we'll let other parts of monotone + //handle the invalid key option. + app.work.set_ws_options(database_option, branch_option, + key_option, keydir_option); + output << user_output << "\n"; +} // Name: get_content_changed // Arguments: // 1: a revision ID ============================================================ --- monotone.texi fafb2b73256c554045bdfce2097ba8dddb100adb +++ monotone.texi a5245b9f4fd2968bb6f2cbfd6da4bcf651a6d4c4 @@ -7012,7 +7012,46 @@ @section Automation @end table address@hidden mtn automate set_option @var{option} @var{value} address@hidden @strong address@hidden Arguments: + +The @var{option} argument specifies the option name of the option to be set. +The @var{value} argument specifies the new value for the option. + address@hidden Added in: + +3.1 + address@hidden Purpose: + +Set an option from _MTN/option for the current workspace. + address@hidden Sample output: + address@hidden +$ mtn automate set_option keydir /tmp +/tmp address@hidden verbatim + address@hidden Output format: + +The new option value is written out without modification. + address@hidden Error conditions: + +If the option is unknown, prints an error message to stderr and exits +with status 1. + +If setting the keydir option and the keydir doesn't exist, prints a message +to stderr and exits with status 1. + +If setting key and key doesn't exist in the previously set keydir, prints a +message to stderr and exits with status 1. address@hidden table + + @item mtn automate keys @table @strong ============================================================ --- testsuite.lua 81c8e4aea652fb82e6c5499a6ee9d9a5741da25b +++ testsuite.lua 4e0dbb06b2feea0921ea5febec02e913db2bca07 @@ -697,3 +697,4 @@ table.insert(tests, "export") table.insert(tests, "mkdir") table.insert(tests, "fail_cleanly_when__MTN_format_corrupt") table.insert(tests, "export") +table.insert(tests, "automate_set_option")