Skip to content

Commit

Permalink
Move to go module & improve error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrebodin committed Feb 26, 2021
1 parent 3a8ce1e commit c537655
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 134 deletions.
Binary file added .DS_Store
Binary file not shown.
Empty file added .tmuxctlrc
Empty file.
77 changes: 0 additions & 77 deletions Gopkg.lock

This file was deleted.

50 changes: 0 additions & 50 deletions Gopkg.toml

This file was deleted.

10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,13 @@ test.ci:
@echo "Running test"
@go test -v ./...
.PHONY: test.ci

build:
@echo "Building"
@go build
.PHONY: build

docs:
@echo "Building docs"
@static-docs --in docs --out build
.PHONY: docs
15 changes: 8 additions & 7 deletions cli/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,20 @@ func init() {
test := start.Flag("test", "Test config file").Short('t').Bool()

start.Action(func(ctx *kingpin.ParseContext) error {
fmt.Printf("Start tmux with config file: %v\n", *configPath)

filePath, err := findup.Find(*configPath)
if err != nil {
log.Fatalf("Error locating config file %v\n", err)
kingpin.FatalUsageContext(ctx, "locating config file: %v", err)
}

file, err := os.Open(filePath)
if err != nil {
log.Fatalf("Error openning config file %v\n", err)
kingpin.FatalUsageContext(ctx, "Error openning config file %v\n", err)
}

conf, err := config.Parse(file)
if err != nil {
log.Fatalf("Error parsing %s: %v\n", file.Name(), err)
kingpin.FatalUsageContext(ctx, "Error parsing %s: %v\n", file.Name(), err)
}

// stop after parsing in case of test
Expand All @@ -41,19 +40,21 @@ func init() {
os.Exit(0)
}

fmt.Printf("Start tmux with config file: %v\n", *configPath)

runningSessions, err := tmux.ListSessions()
if err != nil {
log.Fatalf("Error listing running sessions %v\n", err)
kingpin.FatalUsageContext(ctx, "Error listing running sessions %v\n", err)
}

options, err := tmux.GetOptions()
if err != nil {
log.Fatalf("Error getting tmux options %v\n", err)
kingpin.FatalUsageContext(ctx, "Error getting tmux options %v\n", err)
}

sess := builder.NewSession(conf, options)
if _, ok := runningSessions[sess.Name]; ok {
log.Fatalf("Session %s is already running\n", sess.Name)
kingpin.FatalUsageContext(ctx, "Session %s is already running\n", sess.Name)
}

checkError := func(err error) {
Expand Down
15 changes: 15 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module github.com/alexandrebodin/tmuxctl

go 1.15

require (
github.com/BurntSushi/toml v0.3.0
github.com/alecthomas/kingpin v2.2.6+incompatible
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc // indirect
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect
github.com/alexandrebodin/go-findup v0.0.0-20180620214025-59888d10a1b8
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/pkg/browser v0.0.0-20170505125900-c90ca0c84f15
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v1.2.2
)
18 changes: 18 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
github.com/BurntSushi/toml v0.3.0 h1:e1/Ivsx3Z0FVTV0NSOv/aVgbUWyQuzj7DDnFblkRvsY=
github.com/BurntSushi/toml v0.3.0/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/alecthomas/kingpin v2.2.6+incompatible h1:5svnBTFgJjZvGKyYBtMB0+m5wvrbUHiqye8wRJMlnYI=
github.com/alecthomas/kingpin v2.2.6+incompatible/go.mod h1:59OFYbFVLKQKq+mqrL6Rw5bR0c3ACQaawgXx0QYndlE=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc h1:cAKDfWh5VpdgMhJosfJnn5/FoN2SRZ4p7fJNX58YPaU=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alexandrebodin/go-findup v0.0.0-20180620214025-59888d10a1b8 h1:e71cKH3DakMUxuBKDb1v+rWiCfZW+jPGf7jOSFM8VJI=
github.com/alexandrebodin/go-findup v0.0.0-20180620214025-59888d10a1b8/go.mod h1:vUL3dISMHKvXeQYHEJcOjDNQTvOTbIhA024o7/umW1Q=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pkg/browser v0.0.0-20170505125900-c90ca0c84f15 h1:mrI+6Ae64Wjt+uahGe5we/sPS1sXjvfT3YjtawAVgps=
github.com/pkg/browser v0.0.0-20170505125900-c90ca0c84f15/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=

0 comments on commit c537655

Please sign in to comment.