Subversion Repositories Koakuma

Rev

Rev 19 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 nishi 1
#!/usr/bin/env tclsh
2
# $Id: create-project.in 42 2024-10-02 10:23:51Z nishi $
5 nishi 3
package require tdom
12 nishi 4
foreach path [glob "@@PREFIX@@/lib/koakuma/utility/*.tcl"] {
5
	source $path
6
}
19 nishi 7
set dothis ""
4 nishi 8
foreach arg $argv {
9
	if { [string range "$arg" 0 0] == "-" } {
10
		if { "$arg" == "-h" || "$arg" == "--help" } {
19 nishi 11
			puts "Usage: $argv0 \[-u username\] \[-p password\] \[-R rpc_url\]"
4 nishi 12
			puts "You can set the environment variable `KOAKUMA_RPC' to override default RPC URL."
12 nishi 13
			puts "Default: http://127.0.0.1/koakuma/rpc"
4 nishi 14
			exit 0
19 nishi 15
		} elseif { "$arg" == "-u" } {
16
			set dothis "set-username"
17
		} elseif { "$arg" == "-p" } {
18
			set dothis "set-password"
19
		} elseif { "$arg" == "-R" } {
20
			set dothis "set-rpc"
4 nishi 21
		}
19 nishi 22
	} else {
23
		if { "$dothis" == "set-username" } {
24
			::rpc::set-username "$arg"
25
		} elseif { "$dothis" == "set-password" } {
26
			::rpc::set-password "$arg"
27
		} elseif { "$dothis" == "set-rpc" } {
28
			set RPC_URL "$arg"
29
		}
30
		set dothis ""
4 nishi 31
	}
32
}
5 nishi 33
 
34
dom createNodeCmd -tagName "name" -jsonType NONE elementNode keyName
35
dom createNodeCmd -tagName "description" -jsonType NONE elementNode keyDescription
36
dom createNodeCmd -tagName "vcs" -jsonType NONE elementNode keyVCS
37
dom createNodeCmd -tagName "url" -jsonType NONE elementNode keyURL
38
 
39
dom createNodeCmd -jsonType STRING textNode valueString
40
 
41
set doc [dom createDocumentNode]
42
 
43
proc ask_for {show var} {
44
	upvar 1 $var $var
45
	puts -nonewline "$show: "
46
	flush stdout
47
	set $var "[gets stdin]"
48
}
49
 
50
ask_for "Name" name
51
ask_for "Description" description
52
ask_for "VCS" vcs
11 nishi 53
puts "Example URL for CVS: pserver://anon:@cvs.nishi.boats/cvs/nishi@tewi"
5 nishi 54
ask_for "VCS URL" url
55
 
56
$doc appendFromScript {
57
	keyName {valueString "$name"}
58
	keyDescription {valueString "$description"}
59
	keyVCS {valueString "$vcs"}
60
	keyURL {valueString "$url"}
61
}
62
set result [::rpc::send "/create-project" "[$doc asJSON]"]
63
if { [lindex $result 0] == 200 } {
64
} else {
65
	set doc [dom parse -json "[lindex $result 1]"]
66
	puts "Error: [$doc selectNodes "string(/error)"]"
67
}