package cmd

import (
	"fmt"

	"github.com/TheThingsNetwork/ttn/ttnctl/util"
	"github.com/spf13/cobra"
)

var applicationsDeleteCmd = &cobra.Command{
	Use:   "delete",
	Short: "Delete an application",
	Long:  `ttnctl devices delete can be used to delete an application.`,
	Run: func(cmd *cobra.Command, args []string) {
		account := util.GetAccount(ctx)
		appID := util.GetAppID(ctx)

		if !confirm(fmt.Sprintf("Are you sure you want to delete application %s?", appID)) {
			ctx.Info("Not doing anything")
			return
		}

		err := account.DeleteApplication(appID)
		if err != nil {
			ctx.WithError(err).Fatal("Could not delete application")
		}
		util.ForceRefreshToken(ctx)

		ctx.Info("Deleted Application")

	},
示例#2
0
       - Name: default key
         Key:  FZYr01cUhdhY1KBiMghUl+/gXyqXhrF6y+1ww7+DzHg=
         Rights: messages:up:r, messages:down:w

Collaborators:
       - Name: yourname
         Rights: settings, delete, collaborators
`,
	Run: func(cmd *cobra.Command, args []string) {
		account := util.GetAccount(ctx)

		var appID string
		if len(args) == 1 {
			appID = args[0]
		} else {
			appID = util.GetAppID(ctx)
		}

		app, err := account.FindApplication(appID)
		if err != nil {
			ctx.WithError(err).Fatal("Could not find application")
		}

		ctx.Info("Found application")

		fmt.Println()

		fmt.Printf("AppID:   %s\n", app.ID)
		fmt.Printf("Name:    %s\n", app.Name)

		fmt.Println("EUIs:")
示例#3
0
import (
	"github.com/TheThingsNetwork/ttn/ttnctl/util"
	"github.com/apex/log"
	"github.com/spf13/cobra"
	"github.com/spf13/viper"
)

var devicesCmd = &cobra.Command{
	Use:     "devices",
	Aliases: []string{"device"},
	Short:   "Manage devices",
	Long:    `ttnctl devices can be used to manage devices.`,
	PersistentPreRun: func(cmd *cobra.Command, args []string) {
		RootCmd.PersistentPreRun(cmd, args)
		util.GetAccount(ctx)
		ctx.WithFields(log.Fields{
			"AppID":  util.GetAppID(ctx),
			"AppEUI": util.GetAppEUI(ctx),
		}).Info("Using Application")
	},
}

func init() {
	RootCmd.AddCommand(devicesCmd)
	devicesCmd.PersistentFlags().String("app-id", "", "The app ID to use")
	viper.BindPFlag("app-id", devicesCmd.PersistentFlags().Lookup("app-id"))
	devicesCmd.PersistentFlags().String("app-eui", "", "The app EUI to use")
	viper.BindPFlag("app-eui", devicesCmd.PersistentFlags().Lookup("app-eui"))
}