Skip to content

Commit a6bbbb0

Browse files
committed
add flags and docs for the same
1 parent 8dc976a commit a6bbbb0

File tree

3 files changed

+75
-20
lines changed

3 files changed

+75
-20
lines changed

commitlog.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

readme.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,31 @@ also, to get better at nimlang
1010

1111
## Features
1212

13-
- Sort git's logs into `features, fixes, others`
13+
- Categorize git's logs into `["build","chore","ci","docs","feat","fix","perf","refactor","revert","style","test"]`
14+
- Doesn't support scoped commits right now
1415
- That's about it.
1516

17+
## Usage
18+
19+
```sh
20+
# for everything
21+
nimclog
22+
23+
# for a specific range
24+
nimclog --start=<gitrevision> --end=<gitrevision>
25+
26+
# shorthand props for the same
27+
nimclog -s=<gitrevision>
28+
nimclog -e=<gitrevision>
29+
30+
```
31+
1632
## Installation
1733

18-
I'm still testing the cross compiled binaries so you'll have to wait for it.
19-
Till then, you can compile it on your system using `nim` or `nimble`
34+
Cross compiled binaries can be found on the releases pages.
35+
Windows builds have not been tested, please report if you find any issues running them.
36+
37+
You can also compile it on your own system using `nim` or `nimble`
2038

2139
```sh
2240
nimble build

src/clog/clog.nim

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,62 @@
11
import std/os
22
import std/strutils
3+
import std/parseopt
34
import re
45

56

67
type
78
CategoryPair* = object
89
commit: string
910
category: string
10-
11-
12-
proc createInitialCommits*() =
11+
Flags* = object
12+
startCommit: string
13+
endCommit: string
14+
15+
16+
proc readParams():Flags =
17+
var flags = Flags(
18+
startCommit:"",
19+
endCommit:""
20+
)
21+
var resString = ""
22+
23+
for param in commandLineParams():
24+
resString = resString & " " & param
25+
26+
var parser = initOptParser(resString)
27+
28+
while true:
29+
parser.next()
30+
case parser.kind
31+
of cmdEnd: break
32+
of cmdShortOption, cmdLongOption:
33+
if parser.val == "":
34+
echo "hello"
35+
else:
36+
case parser.key
37+
of "s","start":
38+
flags.startCommit = parser.val
39+
of "e","end":
40+
flags.endCommit = parser.val
41+
42+
of cmdArgument:
43+
echo "Argument: ", parser.key
44+
45+
return flags
46+
47+
proc createInitialCommits*(flags:Flags) =
1348
when defined(posix):
14-
# TODO:
15-
# handle params where you get the start and end commit
16-
discard execShellCmd("git log --pretty=oneline > commitlog.md")
49+
var cmd = "git log"
50+
if flags.startCommit != "":
51+
cmd = cmd & " " & flags.startCommit
52+
if flags.endCommit != "":
53+
cmd = cmd & " " & flags.endCommit
54+
cmd = cmd & " --pretty=oneline > commitlog.md"
55+
discard execShellCmd(cmd)
1756

1857

1958
proc categorise*(commit: string): string =
20-
const categories = ["ci", "feat", "fix", "others"]
59+
const categories = ["build","chore","ci","docs","feat","fix","perf","refactor","revert","style","test"]
2160
var selected: string;
2261
for i, cat in categories:
2362
if commit.startsWith(cat & ":"):
@@ -69,12 +108,11 @@ proc clean*() =
69108
removeFile("commitlog.md")
70109

71110
proc clog*() =
72-
createInitialCommits()
73-
var categorizedCommits = processInitialCommits();
74-
printCategorized(categorizedCommits)
75-
clean()
76-
77-
78-
79-
80-
111+
when declared(commandLineParams):
112+
var flags = readParams()
113+
createInitialCommits(flags)
114+
var categorizedCommits = processInitialCommits();
115+
printCategorized(categorizedCommits)
116+
clean()
117+
else:
118+
echo "Failed to execute program..."

0 commit comments

Comments
 (0)