Skip to content

Commit 645f98e

Browse files
authored
feat: add gomod (#1)
* feat: add go.mod * chore: refactor var using one bracket * chore: refactor template * feat: colored questions * chore: refactor template * feat: show banner when -h flag present * chore: refactor version to dev * chore: update readme * chore: refactor questions * chore: update readme, add more project descriptions * chore: fix link template
1 parent 464f05d commit 645f98e

File tree

4 files changed

+103
-24
lines changed

4 files changed

+103
-24
lines changed

README.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Anoman
22

3-
Very simple markdown generator for your repository
3+
Very simple README generator for your repository
44

55
#
66

@@ -17,11 +17,39 @@ $
1717
$ echo just answer the given questions :)
1818
$
1919
$ project name ? : Anoman
20-
$ subtitle ? : anoman obong
21-
$ author name ? : Wuriyanto
20+
$
21+
$ website ? : www.anoman.com
22+
$
23+
$ project descriptions ? : README Generator for your project
24+
$
25+
$ notice ? : this project still in development, but ready to use
26+
$
27+
$ author name ? : golangid
28+
$
2229
$ year ? : 2019
2330
```
2431

32+
#### Result
33+
<div align="center">
34+
<h1>ANOMAN</h1>
35+
www.anoman.com
36+
</div>
37+
38+
### What is Anoman?
39+
README Generator for your project
40+
41+
> #### Important Notice
42+
> this project still in development, but ready to use
43+
44+
### Usage:
45+
- one
46+
- two
47+
- three
48+
49+
#
50+
### Author
51+
**golangid 2019**
52+
2553
#
2654

2755
### Golangid 2019

anoman.go

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,73 @@ import (
55
"flag"
66
"fmt"
77
"os"
8+
"runtime"
89
"strings"
910
)
1011

12+
const (
13+
//Version of anoman
14+
Version = "dev"
15+
// Banner of anoman
16+
Banner = `
17+
_________________________________
18+
| |_*_| | \| | | |\/| |_*_| | \| |
19+
| | | |\ \ |__| | | | | |\ | |
20+
***********************************
21+
`
22+
)
23+
1124
var (
1225
questions = []string{
1326
"project name ?",
14-
"subtitle ?",
27+
"website ?",
28+
"project descriptions ?",
29+
"notice ?",
1530
"author name ?",
1631
"year ?",
1732
}
1833
)
1934

2035
func main() {
2136
var (
22-
outputName string
37+
outputName string
38+
showVersion bool
39+
templateMD TemplateMD
40+
responses []string
2341
)
2442

2543
flag.StringVar(&outputName, "output", "out.md", "output markdown name")
2644
flag.StringVar(&outputName, "o", "out.md", "output markdown name")
45+
flag.BoolVar(&showVersion, "v", false, "show anoman version")
46+
flag.BoolVar(&showVersion, "version", false, "show anoman version")
47+
48+
flag.Usage = func() {
49+
printGreenText(Banner)
50+
fmt.Println()
51+
printGreenText(" **-----------------------------------------------** \n")
52+
fmt.Println()
53+
printGreenText(" Anoman (README Generator for your project) \n")
54+
fmt.Println()
55+
printGreenText(" -o | --output output markdown name eg: -o README.md\n")
56+
printGreenText(" -v | --version show anoman version\n")
57+
printGreenText(" -h | --help show help and usage\n")
58+
fmt.Println()
59+
printGreenText(" **-----------------------------------------------** \n")
60+
fmt.Println()
61+
}
2762

2863
flag.Parse()
2964

30-
reader := bufio.NewReader(os.Stdin)
31-
32-
var (
33-
temp TemplateMD
65+
if showVersion {
66+
printGreenText(fmt.Sprintf("%s version %s (runtime: %s) %s", os.Args[0], Version, runtime.Version(), "\n"))
67+
os.Exit(0)
68+
}
3469

35-
responses []string
36-
)
70+
reader := bufio.NewReader(os.Stdin)
3771

3872
for _, question := range questions {
3973

40-
fmt.Printf("%s : ", question)
74+
printGreenText(fmt.Sprintf("%s : ", question))
4175

4276
response, err := reader.ReadString('\n')
4377
if err != nil {
@@ -47,13 +81,17 @@ func main() {
4781

4882
response = strings.TrimSpace(response)
4983

84+
fmt.Println()
85+
5086
responses = append(responses, response)
5187
}
5288

53-
temp.ProjectName = responses[0]
54-
temp.Subtitle = responses[1]
55-
temp.Author = responses[2]
56-
temp.Year = responses[3]
89+
templateMD.ProjectName = responses[0]
90+
templateMD.Website = responses[1]
91+
templateMD.Description = responses[2]
92+
templateMD.Notice = responses[3]
93+
templateMD.Author = responses[4]
94+
templateMD.Year = responses[5]
5795

5896
// for testing you can use os.Stdin
5997

@@ -70,8 +108,12 @@ func main() {
70108

71109
defer file.Close()
72110

73-
if err := ParseOutput(temp, file); err != nil {
111+
if err := ParseOutput(templateMD, file); err != nil {
74112
fmt.Println(err)
75113
os.Exit(1)
76114
}
77115
}
116+
117+
func printGreenText(s string) {
118+
fmt.Printf("\033[32m%s\033[0m", s)
119+
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module github.com/golangid/anoman

template.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,34 @@ import (
88

99
const (
1010
markdownTemplate = `
11-
### {{toUpper .ProjectName}}
12-
#
13-
{{.Subtitle}}
14-
#
11+
<div align="center">
12+
<h1>{{toUpper .ProjectName}}</h1>
13+
<a href="{{.Website}}">{{.Website}}</a>
14+
</div>
15+
16+
### What is {{.ProjectName}}?
17+
{{.Description}}
18+
19+
> #### Important Notice
20+
> {{.Notice}}
1521
16-
#### Usage:
22+
### Usage:
1723
- one
1824
- two
1925
- three
2026
2127
#
2228
### Author
23-
#### {{.Author}} {{.Year}}
29+
**{{.Author}} {{.Year}}**
2430
`
2531
)
2632

2733
// TemplateMD template
2834
type TemplateMD struct {
2935
ProjectName string
30-
Subtitle string
36+
Website string
37+
Description string
38+
Notice string
3139
Author string
3240
Year string
3341
}

0 commit comments

Comments
 (0)