@@ -10,6 +10,8 @@ import (
1010 "time"
1111
1212 "go.uber.org/zap"
13+ "github.com/spf13/cobra"
14+ "github.com/MakeNowJust/heredoc"
1315
1416 "github.com/PythonHacker24/linux-acl-management-backend/api/routes"
1517 "github.com/PythonHacker24/linux-acl-management-backend/config"
@@ -26,14 +28,47 @@ func exec() error {
2628
2729 /* exec() wraps run() protecting it with user interrupts */
2830
31+ utils .InitLogger (true )
2932 /* zap.L() can be used all over the code for global level logging */
33+
3034 zap .L ().Info ("Logger Initiated ..." )
35+
36+ /* setting up cobra for cli interactions */
37+ var (
38+ configPath string
39+ rootCmd = & cobra.Command {
40+ Use : "laclm <command> <subcommand>" ,
41+ Short : "Backend server for linux acl management" ,
42+ Example : heredoc .Doc (`
43+ $ laclm
44+ $ laclm --config /path/to/config.yaml
45+ ` ),
46+ Run : func (cmd * cobra.Command , args []string ) {
47+ if configPath != "" {
48+ fmt .Printf ("Using config file: %s\n " , configPath )
49+ } else {
50+ fmt .Println ("No config file provided." )
51+ }
52+ },
53+ }
54+ )
55+
56+ /* adding --config arguement */
57+ rootCmd .PersistentFlags ().StringVar (& configPath , "config" , "" , "Path to config file" )
58+
59+ /* Execute the command */
60+ if err := rootCmd .Execute (); err != nil {
61+ zap .L ().Error ("arguements error" ,
62+ zap .Error (err ),
63+ )
64+ os .Exit (1 )
65+ }
3166
3267 /*
3368 load config file
3469 if there is an error in loading the config file, then it will exit with code 1
3570 */
36- config .LoadConfig ("./config.yaml" )
71+ config .LoadConfig (configPath )
3772
3873 /*
3974 load environment variables
@@ -42,7 +77,6 @@ func exec() error {
4277 config .LoadEnv ()
4378
4479 /* true for production, false for development mode */
45- utils .InitLogger (false )
4680
4781 ctx , cancel := context .WithCancel (context .Background ())
4882 defer cancel ()
0 commit comments