Subversion Repositories Koakuma

Rev

Rev 4 | Rev 8 | 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 5 2024-10-01 18:07:27Z nishi $
5 nishi 3
package require tdom
4 nishi 4
set RPC_URL "http://127.0.0.1/koakuma/rpc"
5
foreach arg $argv {
6
	if { [string range "$arg" 0 0] == "-" } {
7
		if { "$arg" == "-h" || "$arg" == "--help" } {
8
			puts "Usage: create-project"
9
			puts "You can set the environment variable `KOAKUMA_RPC' to override default RPC URL."
10
			puts "Default: $RPC_URL"	
11
			exit 0
12
		}
13
	}
14
}
15
foreach path [glob "@@PREFIX@@/lib/koakuma/utility/*.tcl"] {
16
	source $path
17
}
18
if { [info exists "env(KOAKUMA_RPC)"] } {
19
	set RPC_URL "$env(KOAKUMA_RPC)"
20
}
5 nishi 21
set RPC_URL "[regsub {/+$} "$RPC_URL" ""]"
4 nishi 22
puts -nonewline "Authentication: "
23
set status [::rpc::require-auth]
24
if { $status == 1 } {
25
	puts "Required"
26
	if { ![::rpc::ask-auth] } {
27
		puts "Authentication failure"
28
		exit 1
29
	}
30
} elseif { $status < 0 } {
31
	puts "Got forbidden, cannot continue"
32
	exit 1
33
} else {
34
	puts "Not required"
35
}
5 nishi 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 } {
66
} else {
67
	set doc [dom parse -json "[lindex $result 1]"]
68
	puts "Error: [$doc selectNodes "string(/error)"]"
69
}