Browse Source

updated output

bmallred 9 years ago
parent
commit
5fb5986c25
7 changed files with 36 additions and 11 deletions
  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
		cli.StringFlag{
17
		cli.StringFlag{
18
			Name:  "file",
18
			Name:  "file",
19
			Value: "general.ledger",
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
		cli.StringFlag{
21
		cli.StringFlag{
22
			Name:  "date",
22
			Name:  "date",
23
			Value: time.Now().UTC().Format("2006-01-02"),
23
			Value: time.Now().UTC().Format("2006-01-02"),
24
			Usage: "",
24
			Usage: "The transaction date",
25
		},
25
		},
26
		cli.StringFlag{
26
		cli.StringFlag{
27
			Name:  "file",
27
			Name:  "file",
28
			Value: "general.ledger",
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
		cli.StringFlag{
17
		cli.StringFlag{
18
			Name:  "file",
18
			Name:  "file",
19
			Value: "general.ledger",
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
		cli.StringFlag{
17
		cli.StringFlag{
18
			Name:  "file",
18
			Name:  "file",
19
			Value: "general.ledger",
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
		cli.StringFlag{
19
		cli.StringFlag{
20
			Name:  "file",
20
			Name:  "file",
21
			Value: "general.ledger",
21
			Value: "general.ledger",
22
			Usage: "",
22
			Usage: "The ledger file",
23
		},
23
		},
24
		cli.StringFlag{
24
		cli.StringFlag{
25
			Name:  "project",
25
			Name:  "project",
26
			Value: "",
26
			Value: "",
27
			Usage: "",
27
			Usage: "The project name",
28
		},
28
		},
29
		cli.StringFlag{
29
		cli.StringFlag{
30
			Name:  "sort",
30
			Name:  "sort",
31
			Value: "account",
31
			Value: "account",
32
			Usage: "",
32
			Usage: "The sort field",
33
		},
33
		},
34
		cli.BoolFlag{
34
		cli.BoolFlag{
35
			Name:  "asc",
35
			Name:  "asc",
36
			Usage: "",
36
			Usage: "The sort direction",
37
		},
37
		},
38
	},
38
	},
39
}
39
}

+ 1 - 1
commandStatus.go

17
		cli.StringFlag{
17
		cli.StringFlag{
18
			Name:  "file",
18
			Name:  "file",
19
			Value: "general.ledger",
19
			Value: "general.ledger",
20
			Usage: "",
20
			Usage: "The ledger file",
21
		},
21
		},
22
	},
22
	},
23
}
23
}

+ 26 - 1
ledger.go

44
	}
44
	}
45
	sort.Strings(keys)
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
	boom := ""
54
	boom := ""
48
	for _, key := range keys {
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
	return boom
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
}