Skip to content

Commit b5d050c

Browse files
committed
feat: Add cli
1 parent 573e7bf commit b5d050c

File tree

6 files changed

+93
-3
lines changed

6 files changed

+93
-3
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
# clean-architecture-telegram-bot
22

3-
A sample for creating telegram bots in Golang with clean architecture
3+
A sample project for creating telegram bots in Golang with clean architecture.
4+
5+
## /cmd
6+
7+
Main functionality for the bot.

cmd/cli.go

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package cmd
2+
3+
import (
4+
"os"
5+
6+
"github.com/urfave/cli/v2"
7+
)
8+
9+
func Run() error {
10+
app := cli.App{
11+
Name: "Sample-telegram-bot",
12+
Usage: "A sample project for creating telegram bots in Golang with clean architecture",
13+
UsageText: "Sample-telegram-bot [command] serve (s) [command option] debug (d)",
14+
Version: "0.1",
15+
Commands: []*cli.Command{
16+
serveCMD,
17+
},
18+
}
19+
20+
return app.Run(os.Args)
21+
}

cmd/commands.go

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/urfave/cli/v2"
7+
)
8+
9+
var (
10+
serveCMD = &cli.Command{
11+
Name: "serve",
12+
Aliases: []string{"s"},
13+
Usage: "Serving telegram bot",
14+
Action: serve,
15+
Subcommands: []*cli.Command{
16+
debugCMD,
17+
},
18+
}
19+
20+
debugCMD = &cli.Command{
21+
Name: "debug",
22+
Aliases: []string{"d"},
23+
Usage: "Turn on debug mode",
24+
After: serve,
25+
Action: debug,
26+
}
27+
28+
debugMode = false
29+
)
30+
31+
func serve(c *cli.Context) error {
32+
fmt.Printf("Debug mod is: %t\n", debugMode)
33+
fmt.Println("clean-architecture-telegram-bot")
34+
35+
return nil
36+
}
37+
38+
func debug(c *cli.Context) error {
39+
fmt.Println("Debug mode is on")
40+
debugMode = true
41+
42+
return nil
43+
}

go.mod

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
module github.com/barahouei/clean-architecture-telegram-bot
22

33
go 1.20
4+
5+
require github.com/urfave/cli/v2 v2.25.7
6+
7+
require (
8+
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
9+
github.com/russross/blackfriday/v2 v2.1.0 // indirect
10+
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
11+
)

go.sum

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
2+
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
3+
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
4+
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
5+
github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs=
6+
github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
7+
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
8+
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=

main.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
package main
22

3-
import "fmt"
3+
import (
4+
"log"
5+
6+
"github.com/barahouei/clean-architecture-telegram-bot/cmd"
7+
)
48

59
func main() {
6-
fmt.Println("clean-architecture-telegram-bot")
10+
if err := cmd.Run(); err != nil {
11+
log.Fatal(err)
12+
}
713
}

0 commit comments

Comments
 (0)