Subversion Repositories Koakuma

Rev

Rev 5 | Rev 11 | 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 8 2024-10-01 23:05:34Z nishi $
5 nishi 3
package require tdom
4 nishi 4
foreach arg $argv {
5
	if { [string range "$arg" 0 0] == "-" } {
6
		if { "$arg" == "-h" || "$arg" == "--help" } {
7
			puts "Usage: create-project"
8
			puts "You can set the environment variable `KOAKUMA_RPC' to override default RPC URL."
9
			puts "Default: $RPC_URL"	
10
			exit 0
11
		}
12
	}
13
}
14
foreach path [glob "@@PREFIX@@/lib/koakuma/utility/*.tcl"] {
15
	source $path
16
}
17
puts -nonewline "Authentication: "
18
set status [::rpc::require-auth]
19
if { $status == 1 } {
20
	puts "Required"
21
	if { ![::rpc::ask-auth] } {
22
		puts "Authentication failure"
23
		exit 1
24
	}
25
} elseif { $status < 0 } {
26
	puts "Got forbidden, cannot continue"
27
	exit 1
28
} else {
29
	puts "Not required"
30
}
5 nishi 31
 
32
dom createNodeCmd -tagName "name" -jsonType NONE elementNode keyName
33
dom createNodeCmd -tagName "description" -jsonType NONE elementNode keyDescription
34
dom createNodeCmd -tagName "vcs" -jsonType NONE elementNode keyVCS
35
dom createNodeCmd -tagName "url" -jsonType NONE elementNode keyURL
36
 
37
dom createNodeCmd -jsonType STRING textNode valueString
38
 
39
set doc [dom createDocumentNode]
40
 
41
proc ask_for {show var} {
42
	upvar 1 $var $var
43
	puts -nonewline "$show: "
44
	flush stdout
45
	set $var "[gets stdin]"
46
}
47
 
48
ask_for "Name" name
49
ask_for "Description" description
50
ask_for "VCS" vcs
51
ask_for "VCS URL" url
52
 
53
$doc appendFromScript {
54
	keyName {valueString "$name"}
55
	keyDescription {valueString "$description"}
56
	keyVCS {valueString "$vcs"}
57
	keyURL {valueString "$url"}
58
}
59
set result [::rpc::send "/create-project" "[$doc asJSON]"]
60
if { [lindex $result 0] == 200 } {
61
} else {
62
	set doc [dom parse -json "[lindex $result 1]"]
63
	puts "Error: [$doc selectNodes "string(/error)"]"
64
}