diff --git a/cmd/itctl/cmd/common.go b/cmd/itctl/cmd/common.go
deleted file mode 100644
index d7ee64d..0000000
--- a/cmd/itctl/cmd/common.go
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * itd uses bluetooth low energy to communicate with InfiniTime devices
- * Copyright (C) 2021 Arsen Musayelyan
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-package cmd
-
-type DFUProgress struct {
- Received int64 `mapstructure:"recvd"`
- Total int64 `mapstructure:"total"`
-}
diff --git a/cmd/itctl/cmd/firmware.go b/cmd/itctl/firmware/firmware.go
similarity index 91%
rename from cmd/itctl/cmd/firmware.go
rename to cmd/itctl/firmware/firmware.go
index 400d01a..0844ea4 100644
--- a/cmd/itctl/cmd/firmware.go
+++ b/cmd/itctl/firmware/firmware.go
@@ -16,10 +16,11 @@
* along with this program. If not, see .
*/
-package cmd
+package firmware
import (
"github.com/spf13/cobra"
+ "go.arsenm.dev/itd/cmd/itctl/root"
)
// firmwareCmd represents the firmware command
@@ -30,5 +31,5 @@ var firmwareCmd = &cobra.Command{
}
func init() {
- rootCmd.AddCommand(firmwareCmd)
+ root.RootCmd.AddCommand(firmwareCmd)
}
diff --git a/cmd/itctl/cmd/upgrade.go b/cmd/itctl/firmware/upgrade.go
similarity index 96%
rename from cmd/itctl/cmd/upgrade.go
rename to cmd/itctl/firmware/upgrade.go
index df854c7..fb90458 100644
--- a/cmd/itctl/cmd/upgrade.go
+++ b/cmd/itctl/firmware/upgrade.go
@@ -16,7 +16,7 @@
* along with this program. If not, see .
*/
-package cmd
+package firmware
import (
"bufio"
@@ -31,6 +31,12 @@ import (
"go.arsenm.dev/itd/internal/types"
)
+type DFUProgress struct {
+ Received int64 `mapstructure:"recvd"`
+ Total int64 `mapstructure:"total"`
+}
+
+
// upgradeCmd represents the upgrade command
var upgradeCmd = &cobra.Command{
Use: "upgrade",
diff --git a/cmd/itctl/cmd/version.go b/cmd/itctl/firmware/version.go
similarity index 99%
rename from cmd/itctl/cmd/version.go
rename to cmd/itctl/firmware/version.go
index 397587d..8a978b0 100644
--- a/cmd/itctl/cmd/version.go
+++ b/cmd/itctl/firmware/version.go
@@ -16,7 +16,7 @@
* along with this program. If not, see .
*/
-package cmd
+package firmware
import (
"bufio"
diff --git a/cmd/itctl/cmd/address.go b/cmd/itctl/get/address.go
similarity index 99%
rename from cmd/itctl/cmd/address.go
rename to cmd/itctl/get/address.go
index e2f492f..1048a0c 100644
--- a/cmd/itctl/cmd/address.go
+++ b/cmd/itctl/get/address.go
@@ -16,7 +16,7 @@
* along with this program. If not, see .
*/
-package cmd
+package get
import (
"bufio"
diff --git a/cmd/itctl/cmd/battery.go b/cmd/itctl/get/battery.go
similarity index 99%
rename from cmd/itctl/cmd/battery.go
rename to cmd/itctl/get/battery.go
index ab396c0..91a5eb8 100644
--- a/cmd/itctl/cmd/battery.go
+++ b/cmd/itctl/get/battery.go
@@ -16,7 +16,7 @@
* along with this program. If not, see .
*/
-package cmd
+package get
import (
"bufio"
diff --git a/cmd/itctl/cmd/get.go b/cmd/itctl/get/get.go
similarity index 92%
rename from cmd/itctl/cmd/get.go
rename to cmd/itctl/get/get.go
index dfffc77..8b595d4 100644
--- a/cmd/itctl/cmd/get.go
+++ b/cmd/itctl/get/get.go
@@ -16,10 +16,11 @@
* along with this program. If not, see .
*/
-package cmd
+package get
import (
"github.com/spf13/cobra"
+ "go.arsenm.dev/itd/cmd/itctl/root"
)
// getCmd represents the get command
@@ -29,5 +30,5 @@ var getCmd = &cobra.Command{
}
func init() {
- rootCmd.AddCommand(getCmd)
+ root.RootCmd.AddCommand(getCmd)
}
diff --git a/cmd/itctl/cmd/heart.go b/cmd/itctl/get/heart.go
similarity index 99%
rename from cmd/itctl/cmd/heart.go
rename to cmd/itctl/get/heart.go
index 4fc4871..329c82e 100644
--- a/cmd/itctl/cmd/heart.go
+++ b/cmd/itctl/get/heart.go
@@ -16,7 +16,7 @@
* along with this program. If not, see .
*/
-package cmd
+package get
import (
"bufio"
diff --git a/cmd/itctl/cmd/motion.go b/cmd/itctl/get/motion.go
similarity index 99%
rename from cmd/itctl/cmd/motion.go
rename to cmd/itctl/get/motion.go
index 88aa84f..f90d896 100644
--- a/cmd/itctl/cmd/motion.go
+++ b/cmd/itctl/get/motion.go
@@ -16,7 +16,7 @@
* along with this program. If not, see .
*/
-package cmd
+package get
import (
"bufio"
diff --git a/cmd/itctl/cmd/steps.go b/cmd/itctl/get/steps.go
similarity index 99%
rename from cmd/itctl/cmd/steps.go
rename to cmd/itctl/get/steps.go
index 61692a5..6d29d45 100644
--- a/cmd/itctl/cmd/steps.go
+++ b/cmd/itctl/get/steps.go
@@ -16,7 +16,7 @@
* along with this program. If not, see .
*/
-package cmd
+package get
import (
"bufio"
diff --git a/cmd/itctl/main.go b/cmd/itctl/main.go
index 6f390d8..1823a57 100644
--- a/cmd/itctl/main.go
+++ b/cmd/itctl/main.go
@@ -19,9 +19,13 @@
package main
import (
- "os"
+ _ "go.arsenm.dev/itd/cmd/itctl/firmware"
+ _ "go.arsenm.dev/itd/cmd/itctl/get"
+ _ "go.arsenm.dev/itd/cmd/itctl/notify"
+ "go.arsenm.dev/itd/cmd/itctl/root"
+ _ "go.arsenm.dev/itd/cmd/itctl/set"
- "go.arsenm.dev/itd/cmd/itctl/cmd"
+ "os"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
@@ -32,5 +36,5 @@ func init() {
}
func main() {
- cmd.Execute()
+ root.Execute()
}
diff --git a/cmd/itctl/cmd/notify.go b/cmd/itctl/notify/notify.go
similarity index 96%
rename from cmd/itctl/cmd/notify.go
rename to cmd/itctl/notify/notify.go
index ddf8ca3..5238003 100644
--- a/cmd/itctl/cmd/notify.go
+++ b/cmd/itctl/notify/notify.go
@@ -16,7 +16,7 @@
* along with this program. If not, see .
*/
-package cmd
+package notify
import (
"bufio"
@@ -26,6 +26,7 @@ import (
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/spf13/viper"
+ "go.arsenm.dev/itd/cmd/itctl/root"
"go.arsenm.dev/itd/internal/types"
)
@@ -79,5 +80,5 @@ var notifyCmd = &cobra.Command{
}
func init() {
- rootCmd.AddCommand(notifyCmd)
+ root.RootCmd.AddCommand(notifyCmd)
}
diff --git a/cmd/itctl/cmd/root.go b/cmd/itctl/root/root.go
similarity index 86%
rename from cmd/itctl/cmd/root.go
rename to cmd/itctl/root/root.go
index 7a23e7e..209c948 100644
--- a/cmd/itctl/cmd/root.go
+++ b/cmd/itctl/root/root.go
@@ -16,7 +16,7 @@
* along with this program. If not, see .
*/
-package cmd
+package root
import (
"github.com/abiosoft/ishell"
@@ -24,8 +24,8 @@ import (
"github.com/spf13/viper"
)
-// rootCmd represents the base command when called without any subcommands
-var rootCmd = &cobra.Command{
+// RootCmd represents the base command when called without any subcommands
+var RootCmd = &cobra.Command{
Use: "itctl",
Short: "Control the itd daemon for InfiniTime smartwatches",
Run: func(cmd *cobra.Command, args []string) {
@@ -61,16 +61,16 @@ var rootCmd = &cobra.Command{
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
- rootCmd.CompletionOptions.DisableDefaultCmd = true
- cobra.CheckErr(rootCmd.Execute())
+ RootCmd.CompletionOptions.DisableDefaultCmd = true
+ cobra.CheckErr(RootCmd.Execute())
}
func init() {
// Register flag for socket path
- rootCmd.Flags().StringP("socket-path", "s", "", "Path to itd socket")
+ RootCmd.Flags().StringP("socket-path", "s", "", "Path to itd socket")
// Bind flag and environment variable to viper key
- viper.BindPFlag("sockPath", rootCmd.Flags().Lookup("socket-path"))
+ viper.BindPFlag("sockPath", RootCmd.Flags().Lookup("socket-path"))
viper.BindEnv("sockPath", "ITCTL_SOCKET_PATH")
// Set default value for socket path
diff --git a/cmd/itctl/cmd/set.go b/cmd/itctl/set/set.go
similarity index 92%
rename from cmd/itctl/cmd/set.go
rename to cmd/itctl/set/set.go
index 5f6e969..5b2f7fa 100644
--- a/cmd/itctl/cmd/set.go
+++ b/cmd/itctl/set/set.go
@@ -16,10 +16,11 @@
* along with this program. If not, see .
*/
-package cmd
+package set
import (
"github.com/spf13/cobra"
+ "go.arsenm.dev/itd/cmd/itctl/root"
)
// setCmd represents the set command
@@ -29,5 +30,5 @@ var setCmd = &cobra.Command{
}
func init() {
- rootCmd.AddCommand(setCmd)
+ root.RootCmd.AddCommand(setCmd)
}
diff --git a/cmd/itctl/cmd/time.go b/cmd/itctl/set/time.go
similarity index 99%
rename from cmd/itctl/cmd/time.go
rename to cmd/itctl/set/time.go
index e69a2ff..4449943 100644
--- a/cmd/itctl/cmd/time.go
+++ b/cmd/itctl/set/time.go
@@ -16,7 +16,7 @@
* along with this program. If not, see .
*/
-package cmd
+package set
import (
"bufio"