Parcourir la Source

updated output

bmallred 9 ans auparavant
Parent
Commettre
5fb5986c25
7 fichiers modifiés avec 36 ajouts et 11 suppressions
  1. 1 1
      commandClear.go
  2. 2 2
      commandCommit.go
  3. 1 1
      commandCredit.go
  4. 1 1
      commandDebit.go
  5. 4 4
      commandList.go
  6. 1 1
      commandStatus.go
  7. 26 1
      ledger.go

+ 1 - 1
commandClear.go

@ -17,7 +17,7 @@ var commandClear = cli.Command{
17 17
		cli.StringFlag{
18 18
			Name:  "file",
19 19
			Value: "general.ledger",
20
			Usage: "",
20
			Usage: "Clears ledger (this cannot be reversed!)",
21 21
		},
22 22
	},
23 23
}

+ 2 - 2
commandCommit.go

@ -21,12 +21,12 @@ var commandCommit = cli.Command{
21 21
		cli.StringFlag{
22 22
			Name:  "date",
23 23
			Value: time.Now().UTC().Format("2006-01-02"),
24
			Usage: "",
24
			Usage: "The transaction date",
25 25
		},
26 26
		cli.StringFlag{
27 27
			Name:  "file",
28 28
			Value: "general.ledger",
29
			Usage: "",
29
			Usage: "The ledger file to store the transaction",
30 30
		},
31 31
	},
32 32
}

+ 1 - 1
commandCredit.go

@ -17,7 +17,7 @@ var commandCredit = cli.Command{
17 17
		cli.StringFlag{
18 18
			Name:  "file",
19 19
			Value: "general.ledger",
20
			Usage: "",
20
			Usage: "The ledger to store the credit",
21 21
		},
22 22
	},
23 23
}

+ 1 - 1
commandDebit.go

@ -17,7 +17,7 @@ var commandDebit = cli.Command{
17 17
		cli.StringFlag{
18 18
			Name:  "file",
19 19
			Value: "general.ledger",
20
			Usage: "",
20
			Usage: "The ledger to store the debit",
21 21
		},
22 22
	},
23 23
}

+ 4 - 4
commandList.go

@ -19,21 +19,21 @@ var commandList = cli.Command{
19 19
		cli.StringFlag{
20 20
			Name:  "file",
21 21
			Value: "general.ledger",
22
			Usage: "",
22
			Usage: "The ledger file",
23 23
		},
24 24
		cli.StringFlag{
25 25
			Name:  "project",
26 26
			Value: "",
27
			Usage: "",
27
			Usage: "The project name",
28 28
		},
29 29
		cli.StringFlag{
30 30
			Name:  "sort",
31 31
			Value: "account",
32
			Usage: "",
32
			Usage: "The sort field",
33 33
		},
34 34
		cli.BoolFlag{
35 35
			Name:  "asc",
36
			Usage: "",
36
			Usage: "The sort direction",
37 37
		},
38 38
	},
39 39
}

+ 1 - 1
commandStatus.go

@ -17,7 +17,7 @@ var commandStatus = cli.Command{
17 17
		cli.StringFlag{
18 18
			Name:  "file",
19 19
			Value: "general.ledger",
20
			Usage: "",
20
			Usage: "The ledger file",
21 21
		},
22 22
	},
23 23
}

+ 26 - 1
ledger.go

@ -44,9 +44,34 @@ func (l *Ledger) ToString() string {
44 44
	}
45 45
	sort.Strings(keys)
46 46
47
	padLength := 20
48
	for _, key := range keys {
49
		if len(key) > padLength {
50
			padLength = len(key) + 2
51
		}
52
	}
53
47 54
	boom := ""
48 55
	for _, key := range keys {
49
		boom += fmt.Sprintf("%s\t\t%s\n", key, balance[key].FloatString(2))
56
		extra := ""
57
		if balance[key].Sign() == 1 {
58
			extra = "+"
59
		}
60
		boom += fmt.Sprintf("%s%s%s\n", padRight(key, " ", padLength), extra, balance[key].FloatString(2))
50 61
	}
51 62
	return boom
52 63
}
64
65
func padRight(source, c string, length int) string {
66
	for i := len(source); i < length; i++ {
67
		source += c
68
	}
69
	return source
70
}
71
72
func padLeft(source, c string, length int) string {
73
	for i := len(source); i < length; i++ {
74
		source = c + source
75
	}
76
	return source
77
}