refactor: config and remote pkg

This commit is contained in:
2019-02-22 13:08:58 +01:00
parent c437127531
commit d6f41b8105
29 changed files with 247 additions and 1292 deletions

View File

@ -1,6 +1,8 @@
package sensor
import (
"fmt"
"github.com/spf13/cobra"
)
@ -8,12 +10,10 @@ var enabled bool
var sensorLocation, wireID, wirePath string
var addSensorCmd = &cobra.Command{
Use: "add",
Short: "Add Sensor",
Args: cobra.ExactArgs(3),
Run: func(cmd *cobra.Command, args []string) {
},
Use: "add",
Short: "Add Sensor",
Args: cobra.ExactArgs(3),
Example: fmt.Sprintf("flucky sensor add indoor dht11 14\nflucky sensor add --wire-id 28-011432f0bb3d outdoor ds18b20 14"),
}
func init() {

View File

@ -1,24 +1,24 @@
package sensor
import (
"log"
// import (
// "log"
"git.cryptic.systems/fh-trier/go-flucky/pkg/sensor"
"github.com/spf13/cobra"
)
// "git.cryptic.systems/fh-trier/go-flucky/pkg/sensor"
// "github.com/spf13/cobra"
// )
var disableSensorCmd = &cobra.Command{
Use: "disable",
Short: "Disable Sensor",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
// var disableSensorCmd = &cobra.Command{
// Use: "disable",
// Short: "Disable Sensor",
// Args: cobra.ExactArgs(1),
// Run: func(cmd *cobra.Command, args []string) {
if err := sensor.Disable(args[0], configDir); err != nil {
log.Fatal(err)
}
},
}
// if err := sensor.Disable(args[0], configDir); err != nil {
// log.Fatal(err)
// }
// },
// }
func init() {
sensorCmd.AddCommand(disableSensorCmd)
}
// func init() {
// sensorCmd.AddCommand(disableSensorCmd)
// }

View File

@ -1,24 +1,24 @@
package sensor
import (
"log"
// import (
// "log"
"git.cryptic.systems/fh-trier/go-flucky/pkg/sensor"
"github.com/spf13/cobra"
)
// "git.cryptic.systems/fh-trier/go-flucky/pkg/sensor"
// "github.com/spf13/cobra"
// )
var enableSensorCmd = &cobra.Command{
Use: "enable",
Short: "Enable Sensor",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
// var enableSensorCmd = &cobra.Command{
// Use: "enable",
// Short: "Enable Sensor",
// Args: cobra.ExactArgs(1),
// Run: func(cmd *cobra.Command, args []string) {
if err := sensor.Enable(args[0], configDir); err != nil {
log.Fatal(err)
}
},
}
// if err := sensor.Enable(args[0], configDir); err != nil {
// log.Fatal(err)
// }
// },
// }
func init() {
sensorCmd.AddCommand(enableSensorCmd)
}
// func init() {
// sensorCmd.AddCommand(enableSensorCmd)
// }

View File

@ -1,29 +1,29 @@
package sensor
import (
"log"
"os"
// import (
// "log"
// "os"
"git.cryptic.systems/fh-trier/go-flucky/pkg/sensor"
"github.com/spf13/cobra"
)
// "git.cryptic.systems/fh-trier/go-flucky/pkg/sensor"
// "github.com/spf13/cobra"
// )
var quiet bool
// var quiet bool
var listSensorCmd = &cobra.Command{
Use: "ls",
Short: "List Sensors",
Aliases: []string{"list"},
Run: func(cmd *cobra.Command, args []string) {
if err := sensor.Print(os.Stdout, configDir, quiet); err != nil {
log.Fatal(err)
}
},
//28-01143277168e
}
// var listSensorCmd = &cobra.Command{
// Use: "ls",
// Short: "List Sensors",
// Aliases: []string{"list"},
// Run: func(cmd *cobra.Command, args []string) {
// if err := sensor.Print(os.Stdout, configDir, quiet); err != nil {
// log.Fatal(err)
// }
// },
// //28-01143277168e
// }
func init() {
sensorCmd.AddCommand(listSensorCmd)
// func init() {
// sensorCmd.AddCommand(listSensorCmd)
listSensorCmd.Flags().BoolVarP(&quiet, "quiet", "q", false, "List only sensor id's")
}
// listSensorCmd.Flags().BoolVarP(&quiet, "quiet", "q", false, "List only sensor id's")
// }

View File

@ -1,24 +1,24 @@
package sensor
import (
"log"
// import (
// "log"
"git.cryptic.systems/fh-trier/go-flucky/pkg/sensor"
"github.com/spf13/cobra"
)
// "git.cryptic.systems/fh-trier/go-flucky/pkg/sensor"
// "github.com/spf13/cobra"
// )
var rmSensorCmd = &cobra.Command{
Use: "rm",
Short: "Remove Sensor",
Aliases: []string{"remove"},
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
if err := sensor.Remove(args[0], configDir); err != nil {
log.Fatal(err)
}
},
}
// var rmSensorCmd = &cobra.Command{
// Use: "rm",
// Short: "Remove Sensor",
// Aliases: []string{"remove"},
// Args: cobra.ExactArgs(1),
// Run: func(cmd *cobra.Command, args []string) {
// if err := sensor.Remove(args[0], configDir); err != nil {
// log.Fatal(err)
// }
// },
// }
func init() {
sensorCmd.AddCommand(rmSensorCmd)
}
// func init() {
// sensorCmd.AddCommand(rmSensorCmd)
// }

View File

@ -4,16 +4,16 @@ import (
"github.com/spf13/cobra"
)
var configDir string
var cfg string
var sensorCmd = &cobra.Command{
Use: "sensor",
Short: "Manage Sensors",
}
// Execute a
func InitCmd(cmd *cobra.Command, cnf string) {
configDir = cnf
// InitCmd da
func InitCmd(cmd *cobra.Command, config string) {
cfg = config
cmd.AddCommand(sensorCmd)

View File

@ -1,27 +0,0 @@
package sensor
import (
"log"
"git.cryptic.systems/fh-trier/go-flucky/pkg/httpcall"
"github.com/spf13/cobra"
)
var force bool
var syncSensorCmd = &cobra.Command{
Use: "sync",
Short: "Synchronise Sensors with Remote Servers",
Aliases: []string{"synchronize"},
Run: func(cmd *cobra.Command, args []string) {
if err := httpcall.SyncSensors(configDir, force); err != nil {
log.Fatal(err)
}
},
}
func init() {
sensorCmd.AddCommand(syncSensorCmd)
syncSensorCmd.Flags().BoolVarP(&force, "force", "f", false, "Include disabled remote links")
}