foreach path [glob "@@PREFIX@@/lib/koakuma/utility/*.tcl"] {
source $path
}
+set dothis ""
foreach arg $argv {
if { [string range "$arg" 0 0] == "-" } {
if { "$arg" == "-h" || "$arg" == "--help" } {
- puts "Usage: $argv0"
+ puts "Usage: $argv0 \[-u username\] \[-p password\] \[-R rpc_url\]"
puts "You can set the environment variable `KOAKUMA_RPC' to override default RPC URL."
puts "Default: http://127.0.0.1/koakuma/rpc"
exit 0
+ } elseif { "$arg" == "-u" } {
+ set dothis "set-username"
+ } elseif { "$arg" == "-p" } {
+ set dothis "set-password"
+ } elseif { "$arg" == "-R" } {
+ set dothis "set-rpc"
}
+ } else {
+ if { "$dothis" == "set-username" } {
+ ::rpc::set-username "$arg"
+ } elseif { "$dothis" == "set-password" } {
+ ::rpc::set-password "$arg"
+ } elseif { "$dothis" == "set-rpc" } {
+ set RPC_URL "$arg"
+ }
+ set dothis ""
}
}
-::rpc::init
-
dom createNodeCmd -tagName "name" -jsonType NONE elementNode keyName
dom createNodeCmd -tagName "description" -jsonType NONE elementNode keyDescription
dom createNodeCmd -tagName "vcs" -jsonType NONE elementNode keyVCS
return 0
}
proc send {path content} {
- set headers ""
global RPC_URL
- if { "$::rpc::username" != "" } {
- lappend headers "Authorization"
- lappend headers "Basic [::base64::encode -wrapchar "" "$::rpc::username:$::rpc::password"]"
+ set code ""
+ set body ""
+ while 1 {
+ set headers ""
+ if { "$::rpc::username" != "" } {
+ lappend headers "Authorization"
+ lappend headers "Basic [::base64::encode -wrapchar "" "$::rpc::username:$::rpc::password"]"
+ }
+ set tok [::http::geturl "$RPC_URL$path" -headers $headers -type "application/json" -query "$content"]
+ set code [::http::ncode $tok]
+ set body "[::http::data $tok]"
+ ::http::cleanup $tok
+ if { $code == 401 } {
+ ::rpc::ask-auth
+ } else {
+ break
+ }
}
- set tok [::http::geturl "$RPC_URL$path" -headers $headers -type "application/json" -query "$content"]
- set code [::http::ncode $tok]
- set body "[::http::data $tok]"
- ::http::cleanup $tok
lappend result "$code"
lappend result "$body"
return $result