Пример #1
0
package cli

import (
	"fmt"

	"github.com/Castcloud/castcloud-go-server/Godeps/_workspace/src/github.com/spf13/cobra"

	"github.com/Castcloud/castcloud-go-server/api"
)

var usersRemoveCmd = &cobra.Command{
	Use:   "remove <username>",
	Short: "Remove user",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 {
			fmt.Println("Usage: users remove <username>")
			return
		}

		err := api.Store().RemoveUser(args[0])
		if err != nil {
			fmt.Println(err)
		} else {
			fmt.Println("Removed", args[0])
		}
	},
}
Пример #2
0
	"github.com/Castcloud/castcloud-go-server/api"

	. "github.com/Castcloud/castcloud-go-server/api/schema"
)

var usersAddCmd = &cobra.Command{
	Use:   "add <username>",
	Short: "Add new user",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 {
			fmt.Println("Usage: users add <username>")
			return
		}

		user := api.Store().GetUser(args[0])
		if user != nil {
			fmt.Println("Username already in use")
			return
		}

		user = &User{
			Username: args[0],
			Password: getPassword(),
		}

		err := api.Store().AddUser(user)
		if err != nil {
			fmt.Println(err)
		} else {
			fmt.Println("Added", user.Username)
Пример #3
0
package cli

import (
	"fmt"

	"github.com/Castcloud/castcloud-go-server/Godeps/_workspace/src/github.com/spf13/cobra"

	"github.com/Castcloud/castcloud-go-server/api"
)

var usersCmd = &cobra.Command{
	Use:   "users",
	Short: "List users",
	Run: func(cmd *cobra.Command, args []string) {
		users := api.Store().GetUsers()

		if len(users) == 0 {
			fmt.Println("There are no users")
		} else if len(users) == 1 {
			fmt.Println("1 user:"******"users:")
			for _, user := range users {
				fmt.Println(user.Username)
			}
		}
	},
}