From 413a8023f4cfd339a298d475ce234115f9911cdc Mon Sep 17 00:00:00 2001 From: Yawning Angel Date: Thu, 23 Jul 2020 13:34:21 +0000 Subject: [PATCH] oasis-core-ledger: Add a basic device listing tool --- .gitignore | 1 + Makefile | 4 ++-- cmd/list.go | 17 ++++++++++++++++ cmd/root.go | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++ go.mod | 7 +++++++ go.sum | 5 ++--- main.go | 10 ++++++++++ 7 files changed, 95 insertions(+), 5 deletions(-) create mode 100644 cmd/list.go create mode 100644 cmd/root.go create mode 100644 main.go diff --git a/.gitignore b/.gitignore index 41e32b0..e3b7149 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ ledger-signer/ledger-signer.so +oasis-core-ledger diff --git a/Makefile b/Makefile index c235cfb..ceb736e 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,12 @@ include common.mk # Set all target as the default target. -all: build-plugin +all: build build-plugin # Build. build: @$(ECHO) "$(MAGENTA)*** Building Go code...$(OFF)" - @$(GO) build -v ./... + @$(GO) build -v . # Build plugin. build-plugin: diff --git a/cmd/list.go b/cmd/list.go new file mode 100644 index 0000000..34d6405 --- /dev/null +++ b/cmd/list.go @@ -0,0 +1,17 @@ +package cmd + +import ( + "github.com/spf13/cobra" + + "github.com/oasisprotocol/oasis-core-ledger/internal" +) + +var listCmd = &cobra.Command{ + Use: "list_devices", + Short: "list available devices by address", + Run: doList, +} + +func doList(cmd *cobra.Command, args []string) { + internal.ListOasisDevices(internal.ListingDerivationPath) +} diff --git a/cmd/root.go b/cmd/root.go new file mode 100644 index 0000000..2fa6f4d --- /dev/null +++ b/cmd/root.go @@ -0,0 +1,56 @@ +// Package cmd implements the oasis-core-ledger tool. +package cmd + +import ( + // "fmt" + + "github.com/spf13/cobra" + // flag "github.com/spf13/pflag" + // "github.com/spf13/viper" + // "github.com/oasisprotocol/oasis-core/go/common/logging" + // "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common" +) + +// const cfgLogLevel = "log.level" + +var rootCmd = &cobra.Command{ + Use: "oasis-core-ledger", + Short: "Oasis Ledger Tool", + Version: "0.0.1", +} + +// rootFlags = flag.NewFlagSet("", flag.ContinueOnError) + +// RootCommand returns the root (top level) cobra.Command. +func RootCommand() *cobra.Command { + return rootCmd +} + +// Execute spawns the main entry point after handling the command line arguments. +func Execute() { + // Blah, The fact that oasis-core imports the ledger library causes + // issues, re-enable logging once the ledger support has been purged. + /* + var logLevel logging.Level + if err := logLevel.Set(viper.GetString(cfgLogLevel)); err != nil { + common.EarlyLogAndExit(fmt.Errorf("root: failed to set log level: %w", err)) + } + + if err := rootCmd.Execute(); err != nil { + common.EarlyLogAndExit(err) + } + */ + _ = rootCmd.Execute() +} + +func init() { // nolint: gochecknoinits + /* + logLevel := logging.LevelInfo + rootFlags.Var(&logLevel, cfgLogLevel, "log level") + _ = viper.BindPFlags(rootFlags) + rootCmd.PersistentFlags().AddFlagSet(rootFlags) + */ + + // Register all of the sub-commands. + rootCmd.AddCommand(listCmd) +} diff --git a/go.mod b/go.mod index fe06de1..23a0567 100644 --- a/go.mod +++ b/go.mod @@ -2,8 +2,15 @@ module github.com/oasisprotocol/oasis-core-ledger go 1.14 +// Updates the version used in spf13/cobra (dependency via tendermint) as +// there is no release yet with the fix. Remove once an updated release of +// spf13/cobra exists and tendermint is updated to include it. +// https://github.com/spf13/cobra/issues/1091 +replace github.com/gorilla/websocket => github.com/gorilla/websocket v1.4.2 + require ( github.com/oasisprotocol/oasis-core/go v0.0.0-20200623153002-9e61aea5195b + github.com/spf13/cobra v1.0.0 github.com/stretchr/testify v1.6.1 github.com/zondax/ledger-go v0.12.0 ) diff --git a/go.sum b/go.sum index 0756baa..9ab9902 100644 --- a/go.sum +++ b/go.sum @@ -235,9 +235,6 @@ github.com/gopherjs/gopherjs v0.0.0-20190910122728-9d188e94fb99/go.mod h1:wJfORR github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= -github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= -github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= -github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= @@ -279,6 +276,7 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg= github.com/huin/goupnp v1.0.0/go.mod h1:n9v9KO1tAxYH82qOn+UTIFQDmx5n1Zxd/ClZDMX7Bnc= github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3iZrZfqZzyLl6l7F3c6L1oWn7OICBi6o= +github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo= github.com/ipfs/go-cid v0.0.1/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM= @@ -709,6 +707,7 @@ github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= +github.com/spf13/cobra v1.0.0 h1:6m/oheQuQ13N9ks4hubMG6BnvwOeaJrqSPLahSnczz8= github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE= github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= diff --git a/main.go b/main.go new file mode 100644 index 0000000..c1c87af --- /dev/null +++ b/main.go @@ -0,0 +1,10 @@ +// Package main implements the oasis-core-ledger CLI tool. +package main + +import ( + "github.com/oasisprotocol/oasis-core-ledger/cmd" +) + +func main() { + cmd.Execute() +}