Subversion Repositories Koakuma

Rev

Rev 12 | Go to most recent revision | 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 19 2024-10-02 07:44:13Z 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"
54
puts "Example URL for CVS: ssh://anoncvs:anoncvs@cvs.nishi.boats/cvs/nishi@tewi"
5 nishi 55
ask_for "VCS URL" url
56
 
57
$doc appendFromScript {
58
	keyName {valueString "$name"}
59
	keyDescription {valueString "$description"}
60
	keyVCS {valueString "$vcs"}
61
	keyURL {valueString "$url"}
62
}
63
set result [::rpc::send "/create-project" "[$doc asJSON]"]
64
if { [lindex $result 0] == 200 } {
65
} else {
66
	set doc [dom parse -json "[lindex $result 1]"]
67
	puts "Error: [$doc selectNodes "string(/error)"]"
68
}