Beispiel #1
0
func ListPlayersHandler(c *cli.Context) error {
	client := client.NewClient(client.BaseURL(c.GlobalString("httpd")))
	players, err := client.Players.List()
	if err != nil {
		return err
	}
	return printPlayers(c.App.Writer, players)
}
Beispiel #2
0
func TestUsersCreate(t *testing.T) {
	s := NewTestServer(t)
	defer s.Close()
	client := client.NewClient(client.BaseURL(s.URL))
	_, err := client.Users.Create(api.User{Name: "brian", Email: "*****@*****.**"})
	if err != nil {
		t.Fatal(err)
	}
}
Beispiel #3
0
func DeleteUsersHandler(c *cli.Context) error {
	client := client.NewClient(client.BaseURL(c.GlobalString("httpd")))
	id, err := strconv.ParseInt(c.Args().First(), 10, 64)
	if err != nil {
		return fmt.Errorf("error parsing user id: %s", err)
	}
	if err := client.Users.Delete(id); err != nil {
		return err
	}
	return nil
}
Beispiel #4
0
func RunMatchesHandler(c *cli.Context) error {
	ID1, err := strconv.ParseInt(c.Args().Get(0), 10, 64)
	if err != nil {
		return err
	}

	ID2, err := strconv.ParseInt(c.Args().Get(1), 10, 64)
	if err != nil {
		return err
	}
	log.Println(ID1, ID2)

	client := client.NewClient(client.BaseURL(c.GlobalString("httpd")))
	match, err := client.Matches.Run(ID1, ID2)
	if err != nil {
		return err
	}
	return printMatches(c.App.Writer, []api.Match{*match})
}
Beispiel #5
0
func CreateUsersHandler(c *cli.Context) error {
	if !c.IsSet("name") {
		return errors.New("name is required")
	}
	n := c.String("name")

	if !c.IsSet("email") {
		return errors.New("email is required")
	}
	e := c.String("email")

	req := api.User{
		Name:  n,
		Email: e,
	}
	client := client.NewClient(client.BaseURL(c.GlobalString("httpd")))
	user, err := client.Users.Create(req)
	if err != nil {
		return err
	}
	return printUsers(c.App.Writer, []api.User{*user})
}
Beispiel #6
0
func CreatePlayersHandler(c *cli.Context) error {

	if !c.IsSet(argName) {
		return ErrArgRequired(argName)
	}
	n := c.String(argName)

	if !c.IsSet(argVer) {
		return ErrArgRequired(argVer)
	}
	v := c.Int(argVer)

	if !c.IsSet(argAuthor) {
		return ErrArgRequired(argAuthor)
	}
	a := c.Int(argAuthor)

	if !c.IsSet(argExe) { // validated last since all other args are simpler to validate
		return ErrArgRequired(argExe)
	}
	f, err := os.Open(c.String(argExe))
	if err != nil {
		return err
	}
	defer f.Close()

	player := api.Player{
		Name:     n,
		Version:  int64(v),
		AuthorId: int64(a),
	}
	client := client.NewClient(client.BaseURL(c.GlobalString("httpd")))
	created, err := client.Players.Upload(int64(a), player, f)
	if err != nil {
		return err
	}
	return printPlayers(c.App.Writer, []api.Player{*created})
}