Open / Close done by qmkenc
This commit is contained in:
parent
f83d8b6a7d
commit
589807368e
67
cmd/root.go
67
cmd/root.go
|
@ -101,6 +101,33 @@ func initInfoType() {
|
|||
}
|
||||
}
|
||||
|
||||
func initQdev() error {
|
||||
actDev := viper.GetString("device.path")
|
||||
if actDev == "" {
|
||||
return fmt.Errorf("No device specified")
|
||||
}
|
||||
|
||||
if viper.GetInt("device.blocksize") == 0 {
|
||||
qdevs, err := qmkenc.QEncScanDevices()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, qd := range qdevs {
|
||||
if qd.GetPath() == actDev {
|
||||
qdev = qd
|
||||
break
|
||||
}
|
||||
}
|
||||
if qdev == nil {
|
||||
err = fmt.Errorf("Device: %s not found\n", actDev)
|
||||
return err
|
||||
}
|
||||
}
|
||||
qdev = qmkenc.QEncNewDevice(actDev, uint8(viper.GetInt("device.blocksize")), viper.GetInt("device.timeout"), viper.GetInt("device.retry_timeout"), viper.GetInt("device.retry_wait"), viper.GetString("lockfile"))
|
||||
return nil
|
||||
}
|
||||
|
||||
// rootCmd represents the base command when called without any subcommands
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "eqmk",
|
||||
|
@ -128,48 +155,10 @@ to decrypt encrypted logins and passwords transparent for browsers.`,
|
|||
|
||||
slog.LOG_DEBUGLN("Root Pre run started")
|
||||
initInfoType()
|
||||
actDev := viper.GetString("device.path")
|
||||
if actDev == "" {
|
||||
slog.LOG_ERRORLN("No device specified")
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
if viper.GetInt("device.blocksize") == 0 {
|
||||
qdevs, err := qmkenc.QEncScanDevices()
|
||||
if err != nil {
|
||||
slog.LOG_ERRORLN(err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
for _, qd := range qdevs {
|
||||
if qd.GetPath() == actDev {
|
||||
qdev = qd
|
||||
break
|
||||
}
|
||||
}
|
||||
if qdev == nil {
|
||||
err = fmt.Errorf("Device: %s not found\n", actDev)
|
||||
slog.LOG_ERRORF("%s\n", err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
}
|
||||
qdev = qmkenc.QEncNewDevice(actDev, uint8(viper.GetInt("device.blocksize")), viper.GetInt("device.timeout"), viper.GetInt("device.retry_timeout"), viper.GetInt("device.retry_wait"), viper.GetString("lockfile"))
|
||||
if err := qdev.Open(); err != nil {
|
||||
slog.LOG_ERRORLN(err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
slog.LOG_DEBUGLN("Open")
|
||||
initQdev()
|
||||
},
|
||||
PersistentPostRun: func(cmd *cobra.Command, args []string) {
|
||||
slog.LOG_DEBUGLN("Finished")
|
||||
if qdev != nil {
|
||||
err := qdev.Close()
|
||||
if err != nil {
|
||||
slog.LOG_ERRORLN(err)
|
||||
}
|
||||
}
|
||||
slog.LOG_DEBUGLN("Removing lockfile")
|
||||
os.Remove(viper.GetString("lockfile"))
|
||||
slog.FINISH()
|
||||
},
|
||||
}
|
||||
|
|
18
go.mod
18
go.mod
|
@ -5,9 +5,8 @@ go 1.18
|
|||
require (
|
||||
gitea.olznet.de/OlzNet/golang-keepassxc-browser v0.9.0
|
||||
gitea.olznet.de/OlzNet/slog v1.3.0
|
||||
gitea.olznet.de/eqmk/qmkenc v0.9.1
|
||||
gitea.olznet.de/eqmk/qmkenc v0.9.2
|
||||
github.com/TheCreeper/go-notify v0.2.0
|
||||
github.com/google/go-containerregistry v0.10.0
|
||||
github.com/manifoldco/promptui v0.9.0
|
||||
github.com/mitchellh/go-homedir v1.1.0
|
||||
github.com/spf13/cobra v1.4.0
|
||||
|
@ -18,38 +17,27 @@ require (
|
|||
|
||||
require (
|
||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
|
||||
github.com/containerd/stargz-snapshotter/estargz v0.11.4 // indirect
|
||||
github.com/docker/cli v20.10.16+incompatible // indirect
|
||||
github.com/docker/distribution v2.8.1+incompatible // indirect
|
||||
github.com/docker/docker v20.10.16+incompatible // indirect
|
||||
github.com/docker/docker-credential-helpers v0.6.4 // indirect
|
||||
github.com/fsnotify/fsnotify v1.5.1 // indirect
|
||||
github.com/godbus/dbus/v5 v5.0.4 // indirect
|
||||
github.com/google/go-cmp v0.5.8 // indirect
|
||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||
github.com/jamesruan/sodium v1.0.14 // indirect
|
||||
github.com/klauspost/compress v1.15.4 // indirect
|
||||
github.com/kr/text v0.2.0 // indirect
|
||||
github.com/magiconair/properties v1.8.6 // indirect
|
||||
github.com/mitchellh/mapstructure v1.4.3 // indirect
|
||||
github.com/opencontainers/go-digest v1.0.0 // indirect
|
||||
github.com/opencontainers/image-spec v1.0.3-0.20220114050600-8b9d41f48198 // indirect
|
||||
github.com/pelletier/go-toml v1.9.4 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.0.0-beta.8 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/sirupsen/logrus v1.8.1 // indirect
|
||||
github.com/spf13/afero v1.8.2 // indirect
|
||||
github.com/spf13/cast v1.4.1 // indirect
|
||||
github.com/spf13/jwalterweatherman v1.1.0 // indirect
|
||||
github.com/sstallion/go-hid v0.0.0-20211019232252-c64377bfa49e // indirect
|
||||
github.com/subosito/gotenv v1.2.0 // indirect
|
||||
github.com/vbatts/tar-split v0.11.2 // indirect
|
||||
golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5 // indirect
|
||||
golang.org/x/image v0.0.0-20211028202545-6944b10bf410 // indirect
|
||||
golang.org/x/mobile v0.0.0-20210716004757-34ab1303b554 // indirect
|
||||
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 // indirect
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
|
||||
golang.org/x/text v0.3.7 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
||||
gopkg.in/ini.v1 v1.66.4 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
|
||||
|
|
Loading…
Reference in New Issue