From 109cc2de8f998401a4756a825b479249dc449fad Mon Sep 17 00:00:00 2001 From: Manfred Touron Date: Fri, 27 Jul 2018 01:50:19 +0200 Subject: [PATCH] feat(core): initial cmd implementation (#47) --- .circleci/config.yml | 10 +++++----- core/Makefile | 6 +++++- core/api/node/version.go | 4 ++++ core/api/p2p/version.go | 3 +++ core/cmd/.gitkeep | 0 core/cmd/berty/client.go | 13 +++++++++++++ core/cmd/berty/daemon.go | 13 +++++++++++++ core/cmd/berty/main.go | 14 ++++++++++++++ core/cmd/berty/root.go | 23 +++++++++++++++++++++++ core/sql/sqlcipher/sqlcipher.go | 2 ++ core/version.go | 4 ++++ 11 files changed, 86 insertions(+), 6 deletions(-) create mode 100644 core/api/node/version.go delete mode 100644 core/cmd/.gitkeep create mode 100644 core/cmd/berty/client.go create mode 100644 core/cmd/berty/daemon.go create mode 100644 core/cmd/berty/main.go create mode 100644 core/cmd/berty/root.go create mode 100644 core/version.go diff --git a/.circleci/config.yml b/.circleci/config.yml index 54a895b5d0..35551ccb8c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -48,11 +48,11 @@ jobs: command: | sudo apt-get update sudo apt-get install libssl1.0-dev - #- run: - # name: install core - # command: | - # cd core - # make install + - run: + name: install core + command: | + cd core + make install - run: name: test core command: | diff --git a/core/Makefile b/core/Makefile index e0b5bc8443..7137900fd5 100644 --- a/core/Makefile +++ b/core/Makefile @@ -9,7 +9,11 @@ CGO_CPPFLAGS ?= -I/usr/local/opt/openssl/include BUILD_ENV ?= CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CPPFLAGS="$(CGO_CPPFLAGS)" .PHONY: all -all: test +all: install + +.PHONY: install +install: + go install -v ./cmd/... .PHONY: test test: generate diff --git a/core/api/node/version.go b/core/api/node/version.go new file mode 100644 index 0000000000..4bb179658e --- /dev/null +++ b/core/api/node/version.go @@ -0,0 +1,4 @@ +package node + +// Version is the node API version +const Version = uint32(1) diff --git a/core/api/p2p/version.go b/core/api/p2p/version.go index df4ddd305b..671efe6d62 100644 --- a/core/api/p2p/version.go +++ b/core/api/p2p/version.go @@ -1 +1,4 @@ package p2p + +// Version is the p2p API version +const Version = uint32(1) diff --git a/core/cmd/.gitkeep b/core/cmd/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/core/cmd/berty/client.go b/core/cmd/berty/client.go new file mode 100644 index 0000000000..28c8f5c86f --- /dev/null +++ b/core/cmd/berty/client.go @@ -0,0 +1,13 @@ +package main + +import "github.com/spf13/cobra" + +func newClientCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "client", + RunE: func(cmd *cobra.Command, args []string) error { + return nil + }, + } + return cmd +} diff --git a/core/cmd/berty/daemon.go b/core/cmd/berty/daemon.go new file mode 100644 index 0000000000..646e21a86b --- /dev/null +++ b/core/cmd/berty/daemon.go @@ -0,0 +1,13 @@ +package main + +import "github.com/spf13/cobra" + +func newDaemonCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "daemon", + RunE: func(cmd *cobra.Command, args []string) error { + return nil + }, + } + return cmd +} diff --git a/core/cmd/berty/main.go b/core/cmd/berty/main.go new file mode 100644 index 0000000000..026ecc3e0e --- /dev/null +++ b/core/cmd/berty/main.go @@ -0,0 +1,14 @@ +package main + +import ( + "fmt" + "os" +) + +func main() { + rootCmd := newRootCommand() + if err := rootCmd.Execute(); err != nil { + fmt.Fprintf(os.Stderr, "%v\n", err) + os.Exit(1) + } +} diff --git a/core/cmd/berty/root.go b/core/cmd/berty/root.go new file mode 100644 index 0000000000..5785ab243d --- /dev/null +++ b/core/cmd/berty/root.go @@ -0,0 +1,23 @@ +package main + +import ( + "fmt" + + "github.com/berty/berty/core" + "github.com/berty/berty/core/api/node" + "github.com/berty/berty/core/api/p2p" + "github.com/spf13/cobra" +) + +func newRootCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "berty", + Version: fmt.Sprintf("%s (p2p=%d, ui=%d)", core.Version, p2p.Version, node.Version), + } + cmd.PersistentFlags().BoolP("help", "h", false, "Print usage") + cmd.AddCommand( + newDaemonCommand(), + newClientCommand(), + ) + return cmd +} diff --git a/core/sql/sqlcipher/sqlcipher.go b/core/sql/sqlcipher/sqlcipher.go index 36dd112cc0..fe3b0ef9e1 100644 --- a/core/sql/sqlcipher/sqlcipher.go +++ b/core/sql/sqlcipher/sqlcipher.go @@ -5,6 +5,8 @@ import ( "github.com/jinzhu/gorm" "github.com/pkg/errors" + + // sqlcipher blank import _ "github.com/xeodou/go-sqlcipher" ) diff --git a/core/version.go b/core/version.go new file mode 100644 index 0000000000..53e0642916 --- /dev/null +++ b/core/version.go @@ -0,0 +1,4 @@ +package core + +// Version is the core semver version +const Version = "1.0.0"