2
1
Fork 0

Adds describe output... but Im not sold on it. Siloing in a branch for now.

This commit is contained in:
sloum 2021-03-28 23:13:23 -07:00
parent 77de8e95af
commit 6051ef6c01
1 changed files with 65 additions and 1 deletions

66
main.go
View File

@ -28,6 +28,7 @@ import (
"os/signal" "os/signal"
"os/user" "os/user"
"path/filepath" "path/filepath"
"strconv"
"strings" "strings"
"syscall" "syscall"
"tildegit.org/sloum/swim/termios" "tildegit.org/sloum/swim/termios"
@ -254,6 +255,59 @@ func SetColorFromFlag(f string) int {
} }
} }
func DescribeFile() {
fmt.Printf("\033[1m%s\033[0m\n\n", fp)
fmt.Printf("\t\033[1m%s\033[0m (%d lanes)\n", board.Title, len(board.Lanes))
users := map[string]bool{}
comments := 0
if len(board.Lanes) > 0 {
for l := range board.Lanes {
storyWord := "stories"
if len(board.Lanes[l].Stories) == 1 {
storyWord = "story"
}
var b strings.Builder
points := 0
for s := range board.Lanes[l].Stories {
pts := "-"
if board.Lanes[l].Stories[s].Points > 0 {
pts = strconv.Itoa(board.Lanes[l].Stories[s].Points)
}
pointWord := "points"
if pts == "1" {
pointWord = "point"
}
b.WriteString(fmt.Sprintf("\t\t\t\033[1m%s\033[0m (%s %s)\n",board.Lanes[l].Stories[s].Title, pts, pointWord))
points += board.Lanes[l].Stories[s].Points
for u := range board.Lanes[l].Stories[s].Users {
users[board.Lanes[l].Stories[s].Users[u]] = true
}
comments += len(board.Lanes[l].Stories[s].Comments)
}
pointWord := "points"
if points == 1 {
pointWord = "point"
}
fmt.Printf("\n\t\t\033[1m%s\033[0m (%d %s - %d %s)\n", board.Lanes[l].Title, len(board.Lanes[l].Stories), storyWord, points, pointWord)
fmt.Print(b.String())
}
userWord := "users"
if len(users) == 1 {
userWord = "user"
}
fmt.Printf("\n\t\033[1m%d %s\033[0m assigned to stories\n", len(users), userWord)
for k := range users {
fmt.Printf("\t\t%s\n", k)
}
commentWord := "comments"
if comments == 1 {
commentWord = "comment"
}
fmt.Printf("\t\033[1m%d %s\033[0m\n", comments, commentWord)
}
Quit()
}
func printHelp() { func printHelp() {
header := `swim - project board header := `swim - project board
@ -280,21 +334,31 @@ Flags:
func main() { func main() {
flag.Usage = printHelp flag.Usage = printHelp
colors := flag.String("color", "", "Color mode: Simple, 256, True, None" ) colors := flag.String("color", "", "Color mode: Simple, 256, True, None" )
describe := flag.Bool("describe", false, "Output data to stdout about the file being passed in, then exit")
flag.Parse() flag.Parse()
args := flag.Args() args := flag.Args()
style.Init(SetColorFromFlag(*colors)) style.Init(SetColorFromFlag(*colors))
cols, rows := termios.GetWindowSize() cols, rows := termios.GetWindowSize()
arg0 := strings.ToLower(args[0])
if len(args) > 0 { if len(args) > 0 {
if strings.ToLower(args[0]) == "init" { if arg0 == "init" {
InitNewBoard() InitNewBoard()
} else { } else {
LoadFile(args[0], cols, rows) LoadFile(args[0], cols, rows)
} }
} else { } else {
if *describe {
fmt.Fprintf(os.Stderr, "Describe what? No path was passed.")
os.Exit(1)
}
fp = "" fp = ""
board = DefaultBoard(cols, rows) board = DefaultBoard(cols, rows)
} }
if *describe {
DescribeFile()
}
// watch for signals, send them to be handled // watch for signals, send them to be handled
c := make(chan os.Signal, 1) c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGTSTP, syscall.SIGCONT, syscall.SIGINT) signal.Notify(c, syscall.SIGTSTP, syscall.SIGCONT, syscall.SIGINT)