Skip to content

Commit

Permalink
Merge pull request #70 from TheThingsNetwork/feature/improve-config
Browse files Browse the repository at this point in the history
Improve source configuration
  • Loading branch information
happyRip committed Apr 24, 2023
2 parents 12b1483 + bc8d4e5 commit 5b1bde1
Show file tree
Hide file tree
Showing 28 changed files with 779 additions and 502 deletions.
24 changes: 11 additions & 13 deletions cmd/application.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2020 The Things Network Foundation, The Things Industries B.V.
// Copyright © 2023 The Things Network Foundation, The Things Industries B.V.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -19,18 +19,16 @@ import (
"go.thethings.network/lorawan-stack-migrate/pkg/source"
)

var (
applicationsCmd = &cobra.Command{
Use: "application [app-id] ...",
Aliases: []string{"applications", "app"},
Short: "Export all devices of an application",
RunE: func(cmd *cobra.Command, args []string) error {
return exportCommand(cmd, args, func(s source.Source, item string) error {
return s.RangeDevices(item, exportCfg.exportDev)
})
},
}
)
var applicationsCmd = &cobra.Command{
Use: "application [app-id] ...",
Aliases: []string{"applications", "app"},
Short: "Export all devices of an application",
RunE: func(cmd *cobra.Command, args []string) error {
return exportCommand(cmd, args, func(s source.Source, item string) error {
return s.RangeDevices(item, exportCfg.exportDev)
})
},
}

func init() {
applicationsCmd.Flags().AddFlagSet(source.FlagSet())
Expand Down
20 changes: 9 additions & 11 deletions cmd/devices.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2020 The Things Network Foundation, The Things Industries B.V.
// Copyright © 2023 The Things Network Foundation, The Things Industries B.V.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -19,16 +19,14 @@ import (
"go.thethings.network/lorawan-stack-migrate/pkg/source"
)

var (
devicesCmd = &cobra.Command{
Use: "device [dev-id] ...",
Short: "Export devices by DevEUI",
Aliases: []string{"end-devices", "end-device", "devices", "dev"},
RunE: func(cmd *cobra.Command, args []string) error {
return exportCommand(cmd, args, exportCfg.exportDev)
},
}
)
var devicesCmd = &cobra.Command{
Use: "device [dev-id] ...",
Short: "Export devices by DevEUI",
Aliases: []string{"end-devices", "end-device", "devices", "dev"},
RunE: func(cmd *cobra.Command, args []string) error {
return exportCommand(cmd, args, exportCfg.exportDev)
},
}

func init() {
devicesCmd.Flags().AddFlagSet(source.FlagSet())
Expand Down
4 changes: 2 additions & 2 deletions cmd/export.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2020 The Things Network Foundation, The Things Industries B.V.
// Copyright © 2023 The Things Network Foundation, The Things Industries B.V.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,7 +31,7 @@ func exportCommand(cmd *cobra.Command, args []string, f func(s source.Source, it
iter = NewListIterator(args)
}

s, err := source.NewSource(ctx, cmd.Flags())
s, err := source.NewSource(ctx)
if err != nil {
return err
}
Expand Down
21 changes: 15 additions & 6 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2020 The Things Network Foundation, The Things Industries B.V.
// Copyright © 2023 The Things Network Foundation, The Things Industries B.V.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -19,13 +19,15 @@ import (
"os"

"github.com/spf13/cobra"
"go.thethings.network/lorawan-stack-migrate/pkg/source"
"go.thethings.network/lorawan-stack/v3/pkg/log"
"go.thethings.network/lorawan-stack/v3/pkg/rpcmiddleware/rpclog"
)

var (
logger *log.Logger
ctx context.Context
rootCfg = &source.RootConfig
exportCfg = exportConfig{}
rootCmd = &cobra.Command{
Use: "ttn-lw-migrate",
Expand Down Expand Up @@ -66,9 +68,16 @@ func Execute() int {
}

func init() {
rootCmd.PersistentFlags().Bool("verbose", false, "Verbose output")
rootCmd.PersistentFlags().Bool("dry-run", false, "Do everything except resetting root and session keys of exported devices")
rootCmd.PersistentFlags().String("frequency-plans-url", "https://raw.githubusercontent.com/TheThingsNetwork/lorawan-frequency-plans/master", "URL for fetching frequency plans")
rootCmd.PersistentFlags().Bool("set-eui-as-id", false, "Use the DevEUI as ID")
rootCmd.PersistentFlags().String("dev-id-prefix", "", "(optional) value to be prefixed to the resulting device IDs")
rootCmd.PersistentFlags().BoolVar(&rootCfg.DryRun,
"dry-run",
false,
"Do everything except resetting root and session keys of exported devices")
rootCmd.PersistentFlags().BoolVar(&rootCfg.Verbose,
"verbose",
false,
"Verbose output")
rootCmd.PersistentFlags().StringVar(&rootCfg.FrequencyPlansURL,
"frequency-plans-url",
"https://raw.githubusercontent.com/TheThingsNetwork/lorawan-frequency-plans/master",
"URL for fetching frequency plans")
}
38 changes: 18 additions & 20 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2020 The Things Network Foundation, The Things Industries B.V.
// Copyright © 2023 The Things Network Foundation, The Things Industries B.V.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -26,25 +26,23 @@ func printVar(k, v string) {
fmt.Printf("%-20s %s\n", k+":", v)
}

var (
versionCmd = &cobra.Command{
Use: "version",
Short: "Print version information",
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Printf("%s: %s\n", cmd.Root().Short, cmd.Root().Name())
printVar("Version", version.Version)
if version.BuildDate != "" {
printVar("Build date", version.BuildDate)
}
if version.GitCommit != "" {
printVar("Git commit", version.GitCommit)
}
printVar("Go version", runtime.Version())
printVar("OS/Arch", runtime.GOOS+"/"+runtime.GOARCH)
return nil
},
}
)
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print version information",
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Printf("%s: %s\n", cmd.Root().Short, cmd.Root().Name())
printVar("Version", version.Version)
if version.BuildDate != "" {
printVar("Build date", version.BuildDate)
}
if version.GitCommit != "" {
printVar("Git commit", version.GitCommit)
}
printVar("Go version", runtime.Version())
printVar("OS/Arch", runtime.GOOS+"/"+runtime.GOARCH)
return nil
},
}

func init() {
rootCmd.AddCommand(versionCmd)
Expand Down
13 changes: 9 additions & 4 deletions pkg/source/chirpstack/chirpstack.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2020 The Things Network Foundation, The Things Industries B.V.
// Copyright © 2023 The Things Network Foundation, The Things Industries B.V.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -14,13 +14,18 @@

package chirpstack

import "go.thethings.network/lorawan-stack-migrate/pkg/source"
import (
"go.thethings.network/lorawan-stack-migrate/pkg/source"
"go.thethings.network/lorawan-stack-migrate/pkg/source/chirpstack/config"
)

func init() {
cfg, flags := config.New()

source.RegisterSource(source.Registration{
Name: "chirpstack",
Description: "Migrate from ChirpStack LoRaWAN Network Server",
FlagSet: flagSet(),
Create: NewSource,
FlagSet: flags,
Create: createNewSource(cfg),
})
}
114 changes: 0 additions & 114 deletions pkg/source/chirpstack/config.go

This file was deleted.

0 comments on commit 5b1bde1

Please sign in to comment.