From 04544b97655f9f4c8a15e44ab284d0f60b955fbb 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 | 3 +++ core/api/p2p/version.go | 2 ++ 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/version.go | 3 +++ 10 files changed, 81 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 54a895b5d02..35551ccb8ca 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 e0b5bc8443e..7137900fd53 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 00000000000..9cb28c5fb3e --- /dev/null +++ b/core/api/node/version.go @@ -0,0 +1,3 @@ +package node + +const Version = uint32(1) diff --git a/core/api/p2p/version.go b/core/api/p2p/version.go index df4ddd305b4..448f78df6a1 100644 --- a/core/api/p2p/version.go +++ b/core/api/p2p/version.go @@ -1 +1,3 @@ package p2p + +const Version = uint32(1) diff --git a/core/cmd/.gitkeep b/core/cmd/.gitkeep deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/core/cmd/berty/client.go b/core/cmd/berty/client.go new file mode 100644 index 00000000000..28c8f5c86f9 --- /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 00000000000..646e21a86b4 --- /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 00000000000..026ecc3e0e6 --- /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 00000000000..5785ab243d5 --- /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/version.go b/core/version.go new file mode 100644 index 00000000000..743ffd4039f --- /dev/null +++ b/core/version.go @@ -0,0 +1,3 @@ +package core + +const Version = "1.0.0"