<commit_before>// Copyright © 2016 The Things Network
// Use of this source code is governed by the MIT license that can be found in the LICENSE file.

package cmd

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

var gatewaysRegisterCmd = &cobra.Command{
	Use:   "register [GatewayID] [FrequencyPlan]",
	Short: "Register a gateway",
	Long:  `ttnctl gateways register can be used to register a gateway`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) != 2 {
			cmd.UsageFunc()(cmd)
			return
		}

		gatewayID := args[0]
		if !validID(gatewayID) {
			ctx.Fatal("Invalid Gateway ID")
		}

		frequencyPlan := args[1]

		act := util.GetAccount(ctx)
		gateway, err := act.RegisterGateway(gatewayID, frequencyPlan, nil)
		if err != nil {
			ctx.WithError(err).Fatal("Could not register gateway")
		}

		util.ForceRefreshToken(ctx)

		ctx.WithField("Gateway ID", gateway.ID).Info("Registered Gateway")
	},
}

func init() {
	gatewaysCmd.AddCommand(gatewaysRegisterCmd)
}
<commit_msg>fixup! Add ttnctl gateway register cmd<commit_after>// Copyright © 2016 The Things Network
// Use of this source code is governed by the MIT license that can be found in the LICENSE file.

package cmd

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

var gatewaysRegisterCmd = &cobra.Command{
	Use:   "register [GatewayID] [FrequencyPlan]",
	Short: "Register a gateway",
	Long:  `ttnctl gateways register can be used to register a gateway`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) != 2 {
			cmd.UsageFunc()(cmd)
			return
		}

		gatewayID := args[0]
		if !api.ValidID(gatewayID) {
			ctx.Fatal("Invalid Gateway ID")
		}

		frequencyPlan := args[1]

		act := util.GetAccount(ctx)
		gateway, err := act.RegisterGateway(gatewayID, frequencyPlan, nil)
		if err != nil {
			ctx.WithError(err).Fatal("Could not register gateway")
		}

		util.ForceRefreshToken(ctx)

		ctx.WithField("Gateway ID", gateway.ID).Info("Registered Gateway")
	},
}

func init() {
	gatewaysCmd.AddCommand(gatewaysRegisterCmd)
}

{'fraction_non_alphanumeric': 0.12723845428840716, 'fraction_numerical': 0.008482563619227144, 'mean_word_length': 4.216216216216216, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2624225', 'n_tokens_mistral': 804, 'n_tokens_neox': 725, 'n_words': 194}