You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

77 lines
2.2 KiB

package main
import (
"fmt"
"os"
"strconv"
"git.sporestack.com/SporeStack/settlers"
)
func usage() {
fmt.Fprintln(os.Stderr, "Usage: settlers <command> [arguments]")
fmt.Fprintln(os.Stderr, "Command: enable <endpoint> <admin token> <customer token> <business token>")
fmt.Fprintln(os.Stderr, "Command: balance <endpoint> <customer token> <business token>")
fmt.Fprintln(os.Stderr, "Command: add <endpoint> <customer token> <business token> <amount>")
fmt.Fprintln(os.Stderr, "Command: subtract <endpoint> <customer token> <business token> <amount>")
fmt.Fprintln(os.Stderr, "Command: deposittoken <customer token>")
fmt.Fprintln(os.Stderr, "Command: depositonlytokenenabled <endpoint> <deposit token> <business token>")
fmt.Fprintln(os.Stderr, "Command: deposit <endpoint> <deposit token> <business token> <amount>")
os.Exit(2)
}
func exactlyArguments(arguments int) {
if len(os.Args) != arguments {
usage()
}
}
func fatalError(err error) {
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func main() {
var err error
var amount uint64
if len(os.Args) <= 1 {
usage()
}
switch os.Args[1] {
case "enable":
exactlyArguments(2 + 4)
fatalError(settlers.Enable(os.Args[1+1], os.Args[1+2], os.Args[1+3], os.Args[1+4]))
case "balance":
exactlyArguments(2 + 3)
amount, err = settlers.Balance(os.Args[1+1], os.Args[1+2], os.Args[1+3])
fatalError(err)
fmt.Println(amount)
case "deposittoken":
exactlyArguments(2 + 1)
fmt.Println(settlers.DepositToken(os.Args[1+1]))
case "depositonlytokenenabled":
exactlyArguments(2 + 3)
err = settlers.DepositOnlyTokenEnabled(os.Args[1+1], os.Args[1+2], os.Args[1+3])
fatalError(err)
case "deposit":
exactlyArguments(2 + 4)
amount, err = strconv.ParseUint(os.Args[1+4], 10, 64)
fatalError(err)
fatalError(settlers.Deposit(os.Args[1+1], os.Args[1+2], os.Args[1+3], amount))
case "add":
exactlyArguments(2 + 4)
amount, err = strconv.ParseUint(os.Args[1+4], 10, 64)
fatalError(err)
fatalError(settlers.Add(os.Args[1+1], os.Args[1+2], os.Args[1+3], amount))
case "subtract":
exactlyArguments(2 + 4)
amount, err = strconv.ParseUint(os.Args[1+4], 10, 64)
fatalError(err)
fatalError(settlers.Subtract(os.Args[1+1], os.Args[1+2], os.Args[1+3], amount))
default:
usage()
}
}