Skip to content

Commit

Permalink
Add banner and colored log
Browse files Browse the repository at this point in the history
  • Loading branch information
eikendev committed Sep 19, 2021
1 parent f507589 commit c05969c
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 11 deletions.
12 changes: 12 additions & 0 deletions cmd/hackenv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package main
import (
"os"

log "github.com/sirupsen/logrus"

"github.com/eikendev/hackenv/internal/commands"
"github.com/eikendev/hackenv/internal/settings"
"github.com/jessevdk/go-flags"
Expand All @@ -23,6 +25,16 @@ var (
parser = flags.NewParser(&cmds, flags.Default)
)

func init() {
log.SetFormatter(&log.TextFormatter{
DisableTimestamp: true,
})

log.SetOutput(os.Stdout)

log.SetLevel(log.InfoLevel)
}

func main() {
_, err := parser.Parse()
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ go 1.14

require (
github.com/adrg/xdg v0.3.3
github.com/fatih/color v1.12.0 // indirect
github.com/fzipp/gocyclo v0.3.1 // indirect
github.com/jessevdk/go-flags v1.5.0
github.com/melbahja/goph v1.2.1
github.com/schollz/progressbar/v3 v3.8.2
github.com/sirupsen/logrus v1.8.1 // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
golang.org/x/tools v0.1.4 // indirect
Expand Down
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ github.com/adrg/xdg v0.3.3 h1:s/tV7MdqQnzB1nKY8aqHvAMD+uCiuEDzVB5HLRY849U=
github.com/adrg/xdg v0.3.3/go.mod h1:61xAR2VZcggl2St4O9ohF5qCKe08+JDmE4VNzPFQvOQ=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.12.0 h1:mRhaKNwANqRgUBGKmnI5ZxEk7QXmjQeCcuYFMX2bfcc=
github.com/fatih/color v1.12.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
github.com/fzipp/gocyclo v0.3.1 h1:A9UeX3HJSXTBzvHzhqoYVuE0eAhe+aM8XBCCwsPMZOc=
github.com/fzipp/gocyclo v0.3.1/go.mod h1:DJHO6AUmbdqj2ET4Z9iArSuwWgYDRryYt2wASxc7x3E=
github.com/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LFvc=
github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw=
github.com/kr/fs v0.1.0 h1:Jskdu9ieNAYnjxsi0LbQp1ulIKZV1LAFgK1tWhpZgl8=
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.13 h1:qdl+GuBjcsKKDco5BsxPJlId98mSWNKqYA+Co0SC1yA=
github.com/mattn/go-isatty v0.0.13/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
Expand All @@ -28,7 +34,10 @@ github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ
github.com/schollz/progressbar v1.0.0 h1:gbyFReLHDkZo8mxy/dLWMr+Mpb1MokGJ1FqCiqacjZM=
github.com/schollz/progressbar/v3 v3.8.2 h1:2kZJwZCpb+E/V79kGO7daeq+hUwUJW0A5QD1Wv455dA=
github.com/schollz/progressbar/v3 v3.8.2/go.mod h1:9KHLdyuXczIsyStQwzvW8xiELskmX7fQMaZdN23nAv8=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
Expand Down Expand Up @@ -60,6 +69,7 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201218084310-7d0127a74742/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
24 changes: 24 additions & 0 deletions internal/banner/banner.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package banner

import (
"fmt"
"os"

"github.com/fatih/color"
)

const banner = `
__ __
/ /_ ____ ______/ /_____ ____ _ __
/ __ \/ __ ` + "`" + `/ ___/ //_/ _ \/ __ \ | / /
/ / / / /_/ / /__/ ,< / __/ / / / |/ /
/_/ /_/\__,_/\___/_/|_|\___/_/ /_/|___/
`

func PrintBanner() {
fmt.Fprint(os.Stderr, banner)
fmt.Fprintln(os.Stderr, "")
fmt.Fprint(os.Stderr, " ")
color.New(color.FgBlue).Fprintln(os.Stderr, "@eikendev")
fmt.Fprintln(os.Stderr, "")
}
2 changes: 1 addition & 1 deletion internal/commands/down.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package commands

import (
"log"
log "github.com/sirupsen/logrus"

"github.com/eikendev/hackenv/internal/images"
"github.com/eikendev/hackenv/internal/libvirt"
Expand Down
3 changes: 2 additions & 1 deletion internal/commands/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"crypto/sha256"
"fmt"
"io"
"log"
"net/http"
"os"

log "github.com/sirupsen/logrus"

"github.com/eikendev/hackenv/internal/images"
"github.com/eikendev/hackenv/internal/settings"
progressbar "github.com/schollz/progressbar/v3"
Expand Down
3 changes: 2 additions & 1 deletion internal/commands/gui.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package commands

import (
"log"
"os"
"os/exec"

log "github.com/sirupsen/logrus"

"github.com/eikendev/hackenv/internal/constants"
"github.com/eikendev/hackenv/internal/images"
"github.com/eikendev/hackenv/internal/libvirt"
Expand Down
3 changes: 2 additions & 1 deletion internal/commands/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package commands

import (
"fmt"
"log"
"os"
"syscall"

log "github.com/sirupsen/logrus"

"github.com/eikendev/hackenv/internal/constants"
"github.com/eikendev/hackenv/internal/images"
"github.com/eikendev/hackenv/internal/libvirt"
Expand Down
3 changes: 2 additions & 1 deletion internal/commands/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package commands

import (
"fmt"
"log"

log "github.com/sirupsen/logrus"

"github.com/eikendev/hackenv/internal/images"
"github.com/eikendev/hackenv/internal/libvirt"
Expand Down
6 changes: 5 additions & 1 deletion internal/commands/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package commands
import (
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"time"

log "github.com/sirupsen/logrus"

"github.com/eikendev/hackenv/internal/banner"
"github.com/eikendev/hackenv/internal/constants"
"github.com/eikendev/hackenv/internal/host"
"github.com/eikendev/hackenv/internal/images"
Expand Down Expand Up @@ -190,6 +192,8 @@ func ensureSSHKeypairExists() error {
}

func (c *UpCommand) Run(s *settings.Settings) {
banner.PrintBanner()

image := images.GetImageDetails(s.Type)

localPath := image.GetLatestPath()
Expand Down
3 changes: 2 additions & 1 deletion internal/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package host

import (
"bufio"
"log"
"net"
"os/exec"
"strings"

log "github.com/sirupsen/logrus"

"github.com/eikendev/hackenv/internal/paths"
)

Expand Down
3 changes: 2 additions & 1 deletion internal/images/generic.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package images

import (
"log"
"strconv"
"strings"
"time"

log "github.com/sirupsen/logrus"

rawLibvirt "libvirt.org/libvirt-go"
)

Expand Down
3 changes: 2 additions & 1 deletion internal/images/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package images

import (
"fmt"
"log"
"path/filepath"
"regexp"
"time"

log "github.com/sirupsen/logrus"

"github.com/adrg/xdg"
"github.com/eikendev/hackenv/internal/constants"
rawLibvirt "libvirt.org/libvirt-go"
Expand Down
3 changes: 2 additions & 1 deletion internal/libvirt/libvirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package libvirt

import (
"errors"
"log"

log "github.com/sirupsen/logrus"

"github.com/eikendev/hackenv/internal/constants"
"github.com/eikendev/hackenv/internal/images"
Expand Down
3 changes: 2 additions & 1 deletion internal/paths/paths.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package paths

import (
"log"
"os"
"os/exec"
"path/filepath"

log "github.com/sirupsen/logrus"

"github.com/adrg/xdg"
"github.com/eikendev/hackenv/internal/constants"
)
Expand Down

0 comments on commit c05969c

Please sign in to comment.