From 362987c1d86664630b8f9ade2f31384b4c76feab Mon Sep 17 00:00:00 2001 From: Miguel Mota Date: Fri, 27 Apr 2018 17:07:13 -0700 Subject: [PATCH] brew test --- Makefile | 3 +++ cointop.rb | 11 ++++------- cointop/cointop.go | 20 +++++++++++--------- main.go | 28 ++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index c0f83ad..afc1dbc 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,9 @@ clean: test: go test ./... +cointop/test: + go run main.go -test + snap/clean: snapcraft clean diff --git a/cointop.rb b/cointop.rb index eb279b4..c6f1760 100644 --- a/cointop.rb +++ b/cointop.rb @@ -3,21 +3,18 @@ class Cointop < Formula homepage "https://cointop.sh" url "https://github.com/miguelmota/cointop/archive/1.0.0.tar.gz" sha256 "8ff6988cd18b35dbf85436add19135a587e03702b43744f563f137bb067f6e04" - revision 1 - head "https://github.com/miguelmota/cointop.git" depends_on "go" => :build def install ENV["GOPATH"] = buildpath - mkdir "#{buildpath}/src/github.com/miguelmota/cointop" - path = buildpath/"src/github.com/miguelmota/cointop" - cd path do - system "git", "clone", "https://github.com/miguelmota/cointop.git", "." + (buildpath/"src/github.com/miguelmota/cointop").install buildpath.children + cd "src/github.com/miguelmota/cointop" do system "go", "build", "-o", "#{bin}/cointop" + prefix.install_metafiles end end test do - system "true" + system "#{bin}/cointop" "-test" end end diff --git a/cointop/cointop.go b/cointop/cointop.go index 01ab69b..23b12d2 100644 --- a/cointop/cointop.go +++ b/cointop/cointop.go @@ -1,8 +1,6 @@ package cointop import ( - "flag" - "fmt" "log" "os" "sync" @@ -60,15 +58,11 @@ type Cointop struct { helpvisible bool } +// Instance running cointop instance +var Instance *Cointop + // Run runs cointop func Run() { - var ver bool - flag.BoolVar(&ver, "v", false, "Version") - flag.Parse() - if ver { - fmt.Println("1.0.0") - return - } var debug bool if os.Getenv("DEBUG") != "" { debug = true @@ -95,6 +89,7 @@ func Run() { searchfieldviewname: "searchfield", helpviewname: "help", } + Instance = &ct err := ct.setupConfig() if err != nil { log.Fatal(err) @@ -140,3 +135,10 @@ func (ct *Cointop) quit() error { func (ct *Cointop) forceQuit() error { return gocui.ErrQuit } + +// Exit safely exit application +func Exit() { + if Instance != nil { + Instance.g.Close() + } +} diff --git a/main.go b/main.go index 004cde1..6fe11bf 100644 --- a/main.go +++ b/main.go @@ -1,9 +1,37 @@ package main import ( + "flag" + "fmt" + "time" + "github.com/miguelmota/cointop/cointop" ) +var version = "1.0.0" + func main() { + var ver bool + flag.BoolVar(&ver, "v", false, "Version") + var test bool + flag.BoolVar(&test, "test", false, "Run test") + flag.Parse() + if ver { + fmt.Println(version) + return + } + if test { + runTest() + return + } + cointop.Run() } + +func runTest() { + go func() { + cointop.Run() + }() + time.Sleep(1 * time.Second) + cointop.Exit() +}