Skip to content

Commit

Permalink
Running go fmt.
Browse files Browse the repository at this point in the history
  • Loading branch information
ariasmn committed Jul 24, 2022
1 parent 46f02cb commit 7ffa29e
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 58 deletions.
5 changes: 3 additions & 2 deletions groupparser/groupparser.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build linux || freebsd || openbsd || netbsd
// +build linux freebsd openbsd netbsd

package groupparser
Expand All @@ -13,7 +14,7 @@ import (

type Group struct {
Details user.Group
Users []*user.User
Users []*user.User
}

var parsedGroups []Group
Expand Down Expand Up @@ -62,7 +63,7 @@ func parseLine(line string) (Group, error) {
return group, nil
}

func parseUsers(groupUsernames string) ([]*user.User) {
func parseUsers(groupUsernames string) []*user.User {
usernames := strings.Split(groupUsernames, ",")
users := []*user.User{}

Expand Down
3 changes: 2 additions & 1 deletion groupparser/groupparser_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build linux || freebsd || openbsd || netbsd
// +build linux freebsd openbsd netbsd

package groupparser
Expand All @@ -12,6 +13,6 @@ func TestGetGroups(t *testing.T) {
got := GetGroups()

if reflect.TypeOf(got) != reflect.TypeOf(want) {
t.Errorf("got %q, wanted %q", reflect.TypeOf(got), reflect.TypeOf(want))
t.Errorf("got %q, wanted %q", reflect.TypeOf(got), reflect.TypeOf(want))
}
}
42 changes: 21 additions & 21 deletions internal/tui/common/styles.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,33 @@ import "github.com/charmbracelet/lipgloss"

var (
ListStyle = lipgloss.NewStyle().
Width(35).
MarginTop(1).
PaddingRight(3).
MarginRight(3).
Border(lipgloss.RoundedBorder())
Width(35).
MarginTop(1).
PaddingRight(3).
MarginRight(3).
Border(lipgloss.RoundedBorder())
ListColorStyle = lipgloss.NewStyle().
Background(lipgloss.Color("#3d719c"))
Background(lipgloss.Color("#3d719c"))
ListItemStyle = lipgloss.NewStyle().
PaddingLeft(4)
PaddingLeft(4)
ListSelectedListItemStyle = lipgloss.NewStyle().
PaddingLeft(2).
Foreground(lipgloss.Color("#569cd6"))
PaddingLeft(2).
Foreground(lipgloss.Color("#569cd6"))
DetailStyle = lipgloss.NewStyle().
PaddingTop(2)
PaddingTop(2)
DividerStyle = lipgloss.NewStyle().
Foreground(lipgloss.AdaptiveColor{Light: "#9B9B9B", Dark: "#5C5C5C"}).
PaddingTop(1).
PaddingBottom(1)
Foreground(lipgloss.AdaptiveColor{Light: "#9B9B9B", Dark: "#5C5C5C"}).
PaddingTop(1).
PaddingBottom(1)
TableMainStyle = lipgloss.NewStyle().
Align(lipgloss.Center)
Align(lipgloss.Center)
TableHeaderStyle = lipgloss.NewStyle().
Foreground(lipgloss.Color("#569cd6")).
Bold(true)
Foreground(lipgloss.Color("#569cd6")).
Bold(true)
HeaderStyle = lipgloss.NewStyle().
Foreground(lipgloss.Color("#569cd6")).
PaddingBottom(1).
Bold(true).
Underline(true).
Inline(true)
Foreground(lipgloss.Color("#569cd6")).
PaddingBottom(1).
Bold(true).
Underline(true).
Inline(true)
)
6 changes: 3 additions & 3 deletions internal/tui/group/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type item groupparser.Group
func (i item) FilterValue() string { return i.Details.Name }

type BubbleGroup struct {
list list.Model
list list.Model
viewport viewport.Model
}

Expand All @@ -26,10 +26,10 @@ func InitialModel() BubbleGroup {

func groupToItem(groups []groupparser.Group) []list.Item {
items := make([]list.Item, len(groups))
for i,v := range groups {
for i, v := range groups {
items[i] = item(v)
}

return items

}
}
2 changes: 1 addition & 1 deletion internal/tui/group/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/charmbracelet/lipgloss"
)

func (bg BubbleGroup) Update (msg tea.Msg) (BubbleGroup, tea.Cmd) {
func (bg BubbleGroup) Update(msg tea.Msg) (BubbleGroup, tea.Cmd) {
switch msg := msg.(type) {
case tea.WindowSizeMsg:
horizontal, vertical := common.ListStyle.GetFrameSize()
Expand Down
12 changes: 6 additions & 6 deletions internal/tui/group/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func renderGroupDetails(group user.Group) string {
gid := fmt.Sprintf("\n\nGID: %s\n", group.Gid)
name := fmt.Sprintf("Name: %s\n", group.Name)

return gid+name
return gid + name
}

func renderUserTable(users []*user.User) string {
Expand All @@ -59,11 +59,11 @@ func renderUserTable(users []*user.User) string {
return "No users in this group"
}
rows = append(rows, table.NewRow(table.RowData{
"Username" : user.Username,
"Fullname" : user.Name,
"UID" : user.Uid,
"GID" : user.Gid,
"Home directory" : user.HomeDir,
"Username": user.Username,
"Fullname": user.Name,
"UID": user.Uid,
"GID": user.Gid,
"Home directory": user.HomeDir,
}))
}

Expand Down
16 changes: 8 additions & 8 deletions internal/tui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ const (
)

type model struct {
state state
bu user.BubbleUser
bg group.BubbleGroup
state state
bu user.BubbleUser
bg group.BubbleGroup
width, height int
}

Expand Down Expand Up @@ -63,16 +63,16 @@ func (m model) View() string {

func InitialModel() model {
return model{
state: showUserView,
bu: user.InitialModel(),
bg: group.InitialModel(),
state: showUserView,
bu: user.InitialModel(),
bg: group.InitialModel(),
}
}

func updateByState(m model) (model, tea.Cmd) {
var cmd tea.Cmd
windowSizeMsg := tea.WindowSizeMsg {
Width: m.width,
windowSizeMsg := tea.WindowSizeMsg{
Width: m.width,
Height: m.height,
}

Expand Down
2 changes: 1 addition & 1 deletion internal/tui/user/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"io"

"github.com/charmbracelet/bubbles/list"
"github.com/ariasmn/ugm/internal/tui/common"
"github.com/charmbracelet/bubbles/list"
tea "github.com/charmbracelet/bubbletea"
)

Expand Down
4 changes: 2 additions & 2 deletions internal/tui/user/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type item userparser.User
func (i item) FilterValue() string { return i.Details.Username }

type BubbleUser struct {
list list.Model
list list.Model
viewport viewport.Model
}

Expand All @@ -26,7 +26,7 @@ func InitialModel() BubbleUser {

func userToItem(users []userparser.User) []list.Item {
items := make([]list.Item, len(users))
for i,v := range users {
for i, v := range users {
items[i] = item(v)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/tui/user/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ func (bu BubbleUser) Update(msg tea.Msg) (BubbleUser, tea.Cmd) {

var cmd tea.Cmd
bu.list, cmd = bu.list.Update(msg)

return bu, cmd
}
8 changes: 4 additions & 4 deletions internal/tui/user/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ func renderUserDetails(user user.User) string {
fullname := fmt.Sprintf("Fullname: %s\n", user.Name)
identificators := fmt.Sprintf("UID: %s\nGID: %s\n", user.Uid, user.Gid)
homeDirectory := fmt.Sprintf("Home directory: %s\n", user.HomeDir)
return username+fullname+identificators+homeDirectory

return username + fullname + identificators + homeDirectory
}

func renderGroupTable(groups []*user.Group) string {
rows := []table.Row{}

for _, group := range groups {
rows = append(rows, table.NewRow(table.RowData{
"GID" : group.Gid,
"Name" : group.Name,
"GID": group.Gid,
"Name": group.Name,
}))
}

Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
)

var supportedOS = map[string]bool{
"linux": true,
"linux": true,
"freebsd": true,
"openbsd": true,
"netbsd": true,
"netbsd": true,
}

func main() {
Expand All @@ -23,7 +23,7 @@ func main() {
}

p := tea.NewProgram(tui.InitialModel(), tea.WithAltScreen())

if err := p.Start(); err != nil {
fmt.Printf("Alas, there's been an error: %v", err)
os.Exit(1)
Expand Down
7 changes: 4 additions & 3 deletions userparser/userparser.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build linux || freebsd || openbsd || netbsd
// +build linux freebsd openbsd netbsd

package userparser
Expand All @@ -13,7 +14,7 @@ import (

type User struct {
Details user.User
Groups []*user.Group
Groups []*user.Group
}

var parsedUsers []User
Expand Down Expand Up @@ -68,8 +69,8 @@ func parseLine(line string) (User, error) {
return user, nil
}

func parseGroups(currentUser user.User) ([]*user.Group) {
groupsIds, _:= currentUser.GroupIds()
func parseGroups(currentUser user.User) []*user.Group {
groupsIds, _ := currentUser.GroupIds()
groups := []*user.Group{}

for _, groupId := range groupsIds {
Expand Down
5 changes: 3 additions & 2 deletions userparser/userparser_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build linux || freebsd || openbsd || netbsd
// +build linux freebsd openbsd netbsd

package userparser
Expand All @@ -12,6 +13,6 @@ func TestGetUsers(t *testing.T) {
got := GetUsers()

if reflect.TypeOf(got) != reflect.TypeOf(want) {
t.Errorf("got %q, wanted %q", reflect.TypeOf(got), reflect.TypeOf(want))
}
t.Errorf("got %q, wanted %q", reflect.TypeOf(got), reflect.TypeOf(want))
}
}

0 comments on commit 7ffa29e

Please sign in to comment.