Skip to content

Commit

Permalink
Add: init project
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas Lamirault <nicolas.lamirault@gmail.com>
  • Loading branch information
nlamirault committed Dec 24, 2017
0 parents commit a9b2868
Show file tree
Hide file tree
Showing 480 changed files with 182,867 additions and 0 deletions.
57 changes: 57 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"


[[constraint]]
branch = "master"
name = "github.com/golang/glog"

[[constraint]]
name = "github.com/spf13/cobra"
version = "0.0.1"
120 changes: 120 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Copyright (C) 2017 Nicolas Lamirault <nicolas.lamirault@gmail.com>

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

APP = picsou

VERSION=$(shell \
grep "const Version" version/version.go \
|awk -F'=' '{print $$2}' \
|sed -e "s/[^0-9.]//g" \
|sed -e "s/ //g")

SHELL = /bin/bash

DIR = $(shell pwd)

DOCKER = docker

GO = go

GOX = gox -os="linux darwin windows freebsd openbsd netbsd"
GOX_ARGS = "-output={{.Dir}}-$(VERSION)_{{.OS}}_{{.Arch}}"

BINTRAY_URI = https://api.bintray.com
BINTRAY_USERNAME = nlamirault
BINTRAY_ORG = nlamirault
BINTRAY_REPOSITORY= oss

NO_COLOR=\033[0m
OK_COLOR=\033[32;01m
ERROR_COLOR=\033[31;01m
WARN_COLOR=\033[33;01m

MAKE_COLOR=\033[33;01m%-20s\033[0m

MAIN = github.com/nlamirault/poseidon
SRCS = $(shell git ls-files '*.go' | grep -v '^vendor/')
EXE = $(shell ls poseidon-*_*)

PACKAGE=$(APP)-$(VERSION)
ARCHIVE=$(PACKAGE).tar

.DEFAULT_GOAL := help

.PHONY: help
help:
@echo -e "$(OK_COLOR)==== $(APP) [$(VERSION)] ====$(NO_COLOR)"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "$(MAKE_COLOR) : %s\n", $$1, $$2}'

clean: ## Cleanup
@echo -e "$(OK_COLOR)[$(APP)] Cleanup$(NO_COLOR)"
@rm -fr $(APP) $(EXE) $(APP)-*.tar.gz

.PHONY: init
init: ## Install requirements
@echo -e "$(OK_COLOR)[$(APP)] Install requirements$(NO_COLOR)"
@go get -u github.com/golang/dep/cmd/dep
@go get -u github.com/golang/lint/golint
@go get -u github.com/kisielk/errcheck
@go get -u github.com/mitchellh/gox

.PHONY: deps
deps: ## Install dependencies
@echo -e "$(OK_COLOR)[$(APP)] Update dependencies$(NO_COLOR)"
@dep ensure -update

.PHONY: build
build: ## Make binary
@echo -e "$(OK_COLOR)[$(APP)] Build $(NO_COLOR)"
@$(GO) build .

.PHONY: test
test: ## Launch unit tests
@echo -e "$(OK_COLOR)[$(APP)] Launch unit tests $(NO_COLOR)"
@$(GO) test

.PHONY: lint
lint: ## Launch golint
@$(foreach file,$(SRCS),golint $(file) || exit;)

.PHONY: vet
vet: ## Launch go vet
@$(foreach file,$(SRCS),$(GO) vet $(file) || exit;)

.PHONY: errcheck
errcheck: ## Launch go errcheck
@echo -e "$(OK_COLOR)[$(APP)] Go Errcheck $(NO_COLOR)"
@$(foreach pkg,$(PKGS),errcheck $(pkg) $(glide novendor) || exit;)

.PHONY: coverage
coverage: ## Launch code coverage
@$(foreach pkg,$(PKGS),$(GO) test -cover $(pkg) $(glide novendor) || exit;)

gox: ## Make all binaries
@echo -e "$(OK_COLOR)[$(APP)] Create binaries $(NO_COLOR)"
$(GOX) $(GOX_ARGS) github.com/nlamirault/poseidon

.PHONY: binaries
binaries: ## Upload all binaries
@echo -e "$(OK_COLOR)[$(APP)] Upload binaries to Bintray $(NO_COLOR)"
for i in $(EXE); do \
curl -T $$i \
-u$(BINTRAY_USERNAME):$(BINTRAY_APIKEY) \
"$(BINTRAY_URI)/content/$(BINTRAY_ORG)/$(BINTRAY_REPOSITORY)/$(APP)/${VERSION}/$$i;publish=1"; \
done

# for goprojectile
.PHONY: gopath
gopath:
@echo `pwd`:`pwd`/vendor
60 changes: 60 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (C) 2017 Nicolas Lamirault <nicolas.lamirault@gmail.com>

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
goflag "flag"
"fmt"
"io"
"os"

_ "github.com/golang/glog" // init glog to get its flags
"github.com/spf13/cobra"

pkgcmd "github.com/nlamirault/picsou/pkg/cmd"
)

var (
cliName = "picsou"
helpMessage = "Picsou - CLI to monitor cryptocurrencies"
)

func newPoseidonCommand(out io.Writer) *cobra.Command {
rootCmd := &cobra.Command{
Use: cliName,
Short: "command-line tool to monitor cryptocurrencies",
Long: `The command-line tool to manage cryptocurrencies.`,
}
rootCmd.AddCommand(
newVersionCmd(out, helpMessage),
// newCompletionCommand(out, completionExample),
)
cobra.EnablePrefixMatching = true

// add glog flags
rootCmd.PersistentFlags().AddGoFlagSet(goflag.CommandLine)
// https://github.com/kubernetes/dns/pull/27/files
goflag.CommandLine.Parse([]string{})

return rootCmd
}

func Execute() {
cmd := newPoseidonCommand(os.Stdout)
if err := cmd.Execute(); err != nil {
fmt.Println(pkgcmd.RedOut(err))
os.Exit(1)
}
}
49 changes: 49 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (C) 2017 Nicolas Lamirault <nicolas.lamirault@gmail.com>

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
"fmt"
"io"

"github.com/spf13/cobra"

"github.com/nlamirault/picsou/version"
)

type versionCmd struct {
out io.Writer
}

func newVersionCmd(out io.Writer, help string) *cobra.Command {
versionCmd := &versionCmd{
out: out,
}

cmd := &cobra.Command{
Use: "version",
Short: "Print the version number.",
Long: `All software has versions. This is Poseidon's.`,
RunE: func(cmd *cobra.Command, args []string) error {
return versionCmd.printVersion(help)
},
}
return cmd
}

func (cmd versionCmd) printVersion(help string) error {
fmt.Fprintf(cmd.out, "%s. v%s\n", help, version.Version)
return nil
}
23 changes: 23 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (C) 2017 Nicolas Lamirault <nicolas.lamirault@gmail.com>

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"github.com/nlamirault/picsou/cmd"
)

func main() {
cmd.Execute()
}
25 changes: 25 additions & 0 deletions pkg/cmd/colors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (C) 2017 Nicolas Lamirault <nicolas.lamirault@gmail.com>

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
"github.com/fatih/color"
)

var (
GreenOut = color.New(color.FgGreen).SprintFunc()
YellowOut = color.New(color.FgYellow).SprintFunc()
RedOut = color.New(color.FgRed).SprintFunc()
)
5 changes: 5 additions & 0 deletions vendor/github.com/fatih/color/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions vendor/github.com/fatih/color/LICENSE.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a9b2868

Please sign in to comment.