Subversion Repositories Koakuma

Rev

Rev 4 | Rev 8 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4 Rev 5
Line 1... Line 1...
1
#!/usr/bin/env tclsh
1
#!/usr/bin/env tclsh
-
 
2
# $Id: create-project.in 5 2024-10-01 18:07:27Z nishi $
2
# $Id$
3
package require tdom
3
set RPC_URL "http://127.0.0.1/koakuma/rpc"
4
set RPC_URL "http://127.0.0.1/koakuma/rpc"
4
foreach arg $argv {
5
foreach arg $argv {
5
	if { [string range "$arg" 0 0] == "-" } {
6
	if { [string range "$arg" 0 0] == "-" } {
6
		if { "$arg" == "-h" || "$arg" == "--help" } {
7
		if { "$arg" == "-h" || "$arg" == "--help" } {
7
			puts "Usage: create-project"
8
			puts "Usage: create-project"
Line 15... Line 16...
15
	source $path
16
	source $path
16
}
17
}
17
if { [info exists "env(KOAKUMA_RPC)"] } {
18
if { [info exists "env(KOAKUMA_RPC)"] } {
18
	set RPC_URL "$env(KOAKUMA_RPC)"
19
	set RPC_URL "$env(KOAKUMA_RPC)"
19
}
20
}
-
 
21
set RPC_URL "[regsub {/+$} "$RPC_URL" ""]"
20
puts -nonewline "Authentication: "
22
puts -nonewline "Authentication: "
21
set status [::rpc::require-auth]
23
set status [::rpc::require-auth]
22
if { $status == 1 } {
24
if { $status == 1 } {
23
	puts "Required"
25
	puts "Required"
24
	if { ![::rpc::ask-auth] } {
26
	if { ![::rpc::ask-auth] } {
Line 29... Line 31...
29
	puts "Got forbidden, cannot continue"
31
	puts "Got forbidden, cannot continue"
30
	exit 1
32
	exit 1
31
} else {
33
} else {
32
	puts "Not required"
34
	puts "Not required"
33
}
35
}
-
 
36
 
-
 
37
dom createNodeCmd -tagName "name" -jsonType NONE elementNode keyName
-
 
38
dom createNodeCmd -tagName "description" -jsonType NONE elementNode keyDescription
-
 
39
dom createNodeCmd -tagName "vcs" -jsonType NONE elementNode keyVCS
-
 
40
dom createNodeCmd -tagName "url" -jsonType NONE elementNode keyURL
-
 
41
 
-
 
42
dom createNodeCmd -jsonType STRING textNode valueString
-
 
43
 
-
 
44
set doc [dom createDocumentNode]
-
 
45
 
-
 
46
proc ask_for {show var} {
-
 
47
	upvar 1 $var $var
-
 
48
	puts -nonewline "$show: "
-
 
49
	flush stdout
-
 
50
	set $var "[gets stdin]"
-
 
51
}
-
 
52
 
-
 
53
ask_for "Name" name
-
 
54
ask_for "Description" description
-
 
55
ask_for "VCS" vcs
-
 
56
ask_for "VCS URL" url
-
 
57
 
-
 
58
$doc appendFromScript {
-
 
59
	keyName {valueString "$name"}
-
 
60
	keyDescription {valueString "$description"}
-
 
61
	keyVCS {valueString "$vcs"}
-
 
62
	keyURL {valueString "$url"}
-
 
63
}
-
 
64
set result [::rpc::send "/create-project" "[$doc asJSON]"]
-
 
65
if { [lindex $result 0] == 200 } {
34
::rpc::send
66
} else {
-
 
67
	set doc [dom parse -json "[lindex $result 1]"]
-
 
68
	puts "Error: [$doc selectNodes "string(/error)"]"
-
 
69
}