Skip to content
This repository was archived by the owner on May 3, 2024. It is now read-only.

Commit 5864a63

Browse files
committed
lint, bug fix and dep update
1 parent bbfe2d9 commit 5864a63

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+783
-400
lines changed

Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ generate:
3636
@go generate ./...
3737

3838
lint:
39-
# @go vet $$(go list ./... | grep -v /vendor/)
40-
# @for pkg in $$(go list ./... |grep -v /vendor/ |grep -v /services/) ; do \
41-
# golint -min_confidence=1 $$pkg ; \
42-
# done
39+
@go vet $$(go list ./... | grep -v /vendor/)
40+
@for pkg in $$(go list ./... |grep -v /vendor/ |grep -v /services/) ; do \
41+
golint -min_confidence=1 $$pkg ; \
42+
done
4343

4444
deps:
4545
@go get -u github.com/golang/lint/golint

komanda.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ import (
1515
"gopkg.in/alecthomas/kingpin.v2"
1616
)
1717

18+
// Build value
1819
var Build = ""
1920

2021
var (
2122
app = kingpin.New(komanda.Name, komanda.Description)
2223
ssl = app.Flag("ssl", "enable ssl").Short('s').Bool()
2324

24-
InsecureSkipVerify = app.
25+
insecureSkipVerify = app.
2526
Flag("insecure", "insecure ssl - skip verify. (self-signed certs)").
2627
Short('i').Bool()
2728

@@ -85,8 +86,8 @@ func main() {
8586
config.C.Server.SSL = *ssl
8687
}
8788

88-
if *InsecureSkipVerify {
89-
config.C.Server.Insecure = *InsecureSkipVerify
89+
if *insecureSkipVerify {
90+
config.C.Server.Insecure = *insecureSkipVerify
9091
}
9192

9293
if len(*host) > 0 {

komanda/client/channel.go

+24-9
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,47 @@ import (
1111
"github.com/mephux/komanda-cli/komanda/config"
1212
)
1313

14+
// RenderHandlerFunc type for Exec callbacks
1415
type RenderHandlerFunc func(*Channel, *gocui.View) error
1516

16-
var (
17-
ANSIColors = []int{34, 36, 31, 35, 33, 37, 34, 32, 36, 31, 35, 33}
18-
)
19-
17+
// User struct
2018
type User struct {
2119
Nick string
2220
Mode string
2321
Color int
2422
}
2523

24+
// String converts the user struct to a string
2625
func (u *User) String(c bool) string {
2726
if u == nil {
2827
return ""
2928
}
3029

3130
if c {
3231
return color.Stringf(u.Color, "%s%s", u.Mode, u.Nick)
33-
} else {
34-
return fmt.Sprintf("%s%s", u.Mode, u.Nick)
3532
}
33+
34+
return fmt.Sprintf("%s%s", u.Mode, u.Nick)
3635
}
3736

37+
// NickSorter cast to an array of user pointers
3838
type NickSorter []*User
3939

40-
func (a NickSorter) Len() int { return len(a) }
41-
func (a NickSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
40+
// Len returns the list length
41+
func (a NickSorter) Len() int { return len(a) }
42+
43+
// Swap moves the position of two items in the list
44+
func (a NickSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
45+
46+
// Less checks if i is less than j to change position
4247
func (a NickSorter) Less(i, j int) bool { return a[i].Nick < a[j].Nick }
4348

49+
// Channel struct
4450
type Channel struct {
4551
Status bool
4652
Ready bool
4753
Unread bool
54+
Highlight bool
4855
Name string
4956
Server *Server
5057
MaxX int
@@ -60,6 +67,7 @@ type Channel struct {
6067
mu sync.Mutex
6168
}
6269

70+
// FindUser returns a pointer for a given user or nil
6371
func (channel *Channel) FindUser(nick string) *User {
6472
for _, u := range channel.Users {
6573
if u.Nick == nick {
@@ -70,10 +78,12 @@ func (channel *Channel) FindUser(nick string) *User {
7078
return nil
7179
}
7280

81+
// View returns the channel view
7382
func (channel *Channel) View() (*gocui.View, error) {
7483
return channel.Server.Gui.View(channel.Name)
7584
}
7685

86+
// Update will render the current channel again
7787
func (channel *Channel) Update() (*gocui.View, error) {
7888
channel.MaxX, channel.MaxY = channel.Server.Gui.Size()
7989

@@ -82,6 +92,7 @@ func (channel *Channel) Update() (*gocui.View, error) {
8292

8393
}
8494

95+
// NickListString will ouput the channel users in a pretty format
8596
func (channel *Channel) NickListString(v *gocui.View, c bool) {
8697
sort.Sort(NickSorter(channel.Users))
8798

@@ -98,6 +109,7 @@ func (channel *Channel) NickListString(v *gocui.View, c bool) {
98109
fmt.Fprintf(v, "\n%s", color.String(config.C.Color.Green, "== NICK LIST END\n\n"))
99110
}
100111

112+
// NickMetricsString will output channel metrics in a pretty format
101113
// 09:41 * Irssi: #google-containers: Total of 213 nicks [0 ops, 0 halfops, 0 voices, 213 normal]
102114
func (channel *Channel) NickMetricsString(view *gocui.View) {
103115
var op, hop, v, n int
@@ -119,6 +131,7 @@ func (channel *Channel) NickMetricsString(view *gocui.View) {
119131
color.String(config.C.Color.Green, "**"), channel.Name, len(channel.Users), op, hop, v, n)
120132
}
121133

134+
// RemoveNick from channel list
122135
func (channel *Channel) RemoveNick(nick string) {
123136
for i, user := range channel.Users {
124137
if user.Nick == nick {
@@ -130,6 +143,7 @@ func (channel *Channel) RemoveNick(nick string) {
130143
}
131144
}
132145

146+
// AddNick to channel list
133147
func (channel *Channel) AddNick(nick string) {
134148

135149
if u := channel.FindUser(nick); u == nil {
@@ -145,6 +159,7 @@ func (channel *Channel) AddNick(nick string) {
145159
}
146160
}
147161

162+
// Render the current channel
148163
func (channel *Channel) Render(update bool) error {
149164

150165
view, err := channel.Server.Gui.SetView(channel.Name,
@@ -164,7 +179,7 @@ func (channel *Channel) Render(update bool) error {
164179
view.BgColor = gocui.ColorBlack
165180

166181
if !channel.Private {
167-
fmt.Fprintln(view, "\n\n")
182+
fmt.Fprint(view, "\n\n\n")
168183
} else {
169184
channel.Topic = fmt.Sprintf("Private Chat: %s", channel.Name)
170185
fmt.Fprint(view, "\n\n")

komanda/client/codes.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package client
22

3+
// IrcCodes for message hanlders
4+
// https://www.alien.net.au/irc/irc2numerics.html
35
var IrcCodes = []string{
46
"0",
57
"001",
@@ -42,7 +44,7 @@ var IrcCodes = []string{
4244
"365",
4345
"325",
4446
// "324",
45-
"328",
47+
// "328", // RPL_CHANNEL_URL
4648
// "329",
4749
"331",
4850
// "333",
@@ -53,8 +55,8 @@ var IrcCodes = []string{
5355
"357",
5456
"348",
5557
"349",
56-
"367",
57-
"368",
58+
// "367", // TODO: figure out timestamp
59+
// "368", // TODO: add banlist
5860
"351",
5961
"371",
6062
"374",

komanda/client/connect.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import (
77
ircClient "github.com/fluffle/goirc/client"
88
)
99

10-
// "github.com/thoj/go-ircevent"
11-
10+
// New irc connection
1211
func New(server *Server) *ircClient.Conn {
1312
// irccon := irc.IRC(server.Nick, server.User)
1413
// irccon.VerboseCallbackHandler = false

komanda/client/format.go

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"github.com/mephux/komanda-cli/komanda/config"
1010
)
1111

12+
// StatusMessage will formart a string and write to the status
13+
// channel
1214
func StatusMessage(view *gocui.View, data string) {
1315
timestamp := time.Now().Format(config.C.Time.MessageFormat)
1416

komanda/client/server.go

+47-9
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,19 @@ import (
77
ircClient "github.com/fluffle/goirc/client"
88
"github.com/hectane/go-nonblockingchan"
99
"github.com/jroimartin/gocui"
10+
"github.com/mephux/komanda-cli/komanda/helpers"
1011
)
1112

1213
const (
14+
// StatusChannel default name
1315
StatusChannel = "komanda-status"
1416
)
1517

18+
var (
19+
layoutViews = []string{"header", "input", "menu"}
20+
)
21+
22+
// Server struct
1623
type Server struct {
1724
Gui *gocui.Gui
1825
Client *ircClient.Conn
@@ -35,31 +42,55 @@ type Server struct {
3542
mu sync.Mutex
3643
}
3744

38-
type Handler func(*gocui.Gui, *gocui.View, *Server) error
45+
// Handler type for Exec function returns
46+
type Handler func(*Channel, *gocui.Gui, *gocui.View, *Server) error
3947

48+
// Exec callback for a given channel
4049
func (server *Server) Exec(channel string, h Handler) {
4150
server.Gui.Execute(func(g *gocui.Gui) error {
4251

43-
v, err := g.View(channel)
52+
if helpers.Contains(layoutViews, channel) {
53+
v, err := g.View(channel)
54+
55+
if err != nil {
56+
return err
57+
}
58+
59+
return h(nil, server.Gui, v, server)
60+
}
4461

45-
if err != nil {
62+
c, _, has := server.HasChannel(channel)
63+
64+
if has {
65+
v, err := c.View()
66+
67+
if err != nil {
68+
return err
69+
}
70+
71+
return h(c, server.Gui, v, server)
72+
}
4673

47-
server.NewChannel(channel, false)
74+
server.NewChannel(channel, false)
4875

49-
if v, err := g.View(channel); err == nil {
76+
newC, _, newHas := server.HasChannel(channel)
5077

51-
server.CurrentChannel = channel
78+
if newHas {
79+
v, err := newC.View()
5280

53-
return h(server.Gui, v, server)
81+
if err != nil {
82+
return err
5483
}
5584

56-
return err
85+
server.CurrentChannel = channel
86+
return h(newC, server.Gui, v, server)
5787
}
5888

59-
return h(server.Gui, v, server)
89+
return errors.New("error creating channel")
6090
})
6191
}
6292

93+
// HasChannel returns a channel if it exists in the server channel list
6394
func (server *Server) HasChannel(name string) (*Channel, int, bool) {
6495
for i, channel := range server.Channels {
6596
if name == channel.Name {
@@ -70,6 +101,7 @@ func (server *Server) HasChannel(name string) (*Channel, int, bool) {
70101
return nil, -1, false
71102
}
72103

104+
// FindChannel in server channel list
73105
func (server *Server) FindChannel(name string) *Channel {
74106
c, _, has := server.HasChannel(name)
75107

@@ -80,6 +112,7 @@ func (server *Server) FindChannel(name string) *Channel {
80112
return nil
81113
}
82114

115+
// ChannelView returns a channel view by name or returns an error
83116
func (server *Server) ChannelView(name string) (*gocui.View, error) {
84117
if c, _, ok := server.HasChannel(name); ok {
85118
return c.View()
@@ -89,6 +122,7 @@ func (server *Server) ChannelView(name string) (*gocui.View, error) {
89122

90123
}
91124

125+
// AddChannel to server channel list
92126
func (server *Server) AddChannel(channel *Channel) {
93127

94128
if _, _, ok := server.HasChannel(channel.Name); !ok {
@@ -100,6 +134,7 @@ func (server *Server) AddChannel(channel *Channel) {
100134
}
101135
}
102136

137+
// RemoveChannel will remove a channel from the server channel list
103138
func (server *Server) RemoveChannel(name string) (int, error) {
104139

105140
channel, i, ok := server.HasChannel(name)
@@ -116,6 +151,7 @@ func (server *Server) RemoveChannel(name string) (int, error) {
116151
return 0, nil
117152
}
118153

154+
// GetCurrentChannel will return the current channel in view
119155
func (server *Server) GetCurrentChannel() *Channel {
120156

121157
for _, s := range server.Channels {
@@ -127,13 +163,15 @@ func (server *Server) GetCurrentChannel() *Channel {
127163
return server.Channels[0]
128164
}
129165

166+
// NewChannel will create a channel and add it to the server list
130167
func (server *Server) NewChannel(name string, private bool) error {
131168
maxX, maxY := server.Gui.Size()
132169

133170
channel := Channel{
134171
Topic: "N/A",
135172
Ready: false,
136173
Unread: private,
174+
Highlight: false,
137175
Name: name,
138176
MaxX: maxX,
139177
MaxY: maxY,

komanda/color/color.go

+5
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,27 @@ import (
77
"time"
88
)
99

10+
// Stringf returnrs a color escape string with format options
1011
func Stringf(c int, format string, args ...interface{}) string {
1112
return fmt.Sprintf("\x1b[38;5;%dm%s\x1b[0m", c, fmt.Sprintf(format, args...))
1213
}
1314

15+
// String returns a color escape string
1416
func String(c int, str string) string {
1517
return fmt.Sprintf("\x1b[38;5;%dm%s\x1b[0m", c, str)
1618
}
1719

20+
// StringFormat returns a color escape string with extra options
1821
func StringFormat(c int, str string, args []string) string {
1922
return fmt.Sprintf("\x1b[38;5;%d;%sm%s\x1b[0m", c, strings.Join(args, ";"), str)
2023
}
2124

25+
// StringFormatBoth fg and bg colors
2226
func StringFormatBoth(fg, bg int, str string, args []string) string {
2327
return fmt.Sprintf("\x1b[48;5;%dm\x1b[38;5;%d;%sm%s\x1b[0m", bg, fg, strings.Join(args, ";"), str)
2428
}
2529

30+
// StringRandom returns a random colored string
2631
func StringRandom(str string) string {
2732
return String(Random(22, 231), str)
2833
}

0 commit comments

Comments
 (0)