|
| 1 | + |
| 2 | + |
| 3 | +//////////////////////////////////////////////////////////////////////////// |
| 4 | +// Program: redo |
| 5 | +// Purpose: global option redo |
| 6 | +// Authors: Myself < [email protected]> (c) 2022, All rights reserved |
| 7 | +//////////////////////////////////////////////////////////////////////////// |
| 8 | + |
| 9 | +package main |
| 10 | + |
| 11 | +import ( |
| 12 | +// "fmt" |
| 13 | +// "os" |
| 14 | + |
| 15 | +// "github.com/jessevdk/go-flags" |
| 16 | +) |
| 17 | + |
| 18 | +//////////////////////////////////////////////////////////////////////////// |
| 19 | +// Constant and data type/structure definitions |
| 20 | + |
| 21 | +// The OptsT type defines all the configurable options from cli. |
| 22 | +// type OptsT struct { |
| 23 | +// Host string `short:"H" long:"host" env:"REDO_HOST" description:"host address" default:"localhost"` |
| 24 | +// Port int `short:"p" long:"port" env:"REDO_PORT" description:"listening port" default:"80"` |
| 25 | +// Force bool `short:"f" long:"force" env:"REDO_FORCE" description:"force start"` |
| 26 | +// Verbflg func() `short:"v" long:"verbose" description:"Verbose mode (Multiple -v options increase the verbosity)"` |
| 27 | +// Verbose uint |
| 28 | + |
| 29 | +// } |
| 30 | + |
| 31 | + |
| 32 | +// Template for main starts here |
| 33 | + |
| 34 | +//////////////////////////////////////////////////////////////////////////// |
| 35 | +// Global variables definitions |
| 36 | + |
| 37 | +// var ( |
| 38 | +// progname = "redo" |
| 39 | +// version = "0.1.0" |
| 40 | +// date = "2022-01-17" |
| 41 | + |
| 42 | +// // Opts store all the configurable options |
| 43 | +// Opts OptsT |
| 44 | +// ) |
| 45 | +// |
| 46 | +// var parser = flags.NewParser(&Opts, flags.Default) |
| 47 | + |
| 48 | +//////////////////////////////////////////////////////////////////////////// |
| 49 | +// Function definitions |
| 50 | + |
| 51 | +// Function main |
| 52 | +// func main() { |
| 53 | +// Opts.Verbflg = func() { |
| 54 | +// Opts.Verbose++ |
| 55 | +// } |
| 56 | +// |
| 57 | +// if _, err := parser.Parse(); err != nil { |
| 58 | +// switch flagsErr := err.(type) { |
| 59 | +// case flags.ErrorType: |
| 60 | +// if flagsErr == flags.ErrHelp { |
| 61 | +// os.Exit(0) |
| 62 | +// } |
| 63 | +// os.Exit(1) |
| 64 | +// default: |
| 65 | +// fmt.Println() |
| 66 | +// parser.WriteHelp(os.Stdout) |
| 67 | +// os.Exit(1) |
| 68 | +// } |
| 69 | +// } |
| 70 | +// fmt.Println("") |
| 71 | +// } |
| 72 | +// Template for main ends here |
| 73 | + |
| 74 | + |
| 75 | +// Template for "build" CLI handling starts here |
| 76 | +//////////////////////////////////////////////////////////////////////////// |
| 77 | +// Program: redo |
| 78 | +// Purpose: global option redo |
| 79 | +// Authors: Myself < [email protected]> (c) 2022, All rights reserved |
| 80 | +//////////////////////////////////////////////////////////////////////////// |
| 81 | + |
| 82 | +// package main |
| 83 | + |
| 84 | +// import ( |
| 85 | +// "fmt" |
| 86 | +// "os" |
| 87 | +// ) |
| 88 | + |
| 89 | +// *** Sub-command: build *** |
| 90 | + |
| 91 | +//////////////////////////////////////////////////////////////////////////// |
| 92 | +// Constant and data type/structure definitions |
| 93 | + |
| 94 | +// The BuildCommand type defines all the configurable options from cli. |
| 95 | +// type BuildCommand struct { |
| 96 | +// Dir string `long:"dir" description:"source code root dir" default:"./"` |
| 97 | +// } |
| 98 | + |
| 99 | +// |
| 100 | +// var buildCommand BuildCommand |
| 101 | +// |
| 102 | +// BuildCommand implements the business logic of command `build` |
| 103 | +// func (x *BuildCommand) Execute(args []string) error { |
| 104 | +// fmt.Fprintf(os.Stderr, "Build the network application\n") |
| 105 | +// // fmt.Fprintf(os.Stderr, "Copyright (C) 2022, Myself < [email protected]>\n\n") |
| 106 | +// // fmt.Printf("Doing Build, with %#v\n", args) |
| 107 | +// // fmt.Println(x.Dir) |
| 108 | +// // err := ... |
| 109 | +// return nil |
| 110 | +// } |
| 111 | +// |
| 112 | +// func init() { |
| 113 | +// parser.AddCommand("build", |
| 114 | +// "Build the network application", |
| 115 | +// "Usage:\n redo build [Options] Arch(i386|amd64)", |
| 116 | +// &buildCommand) |
| 117 | +// } |
| 118 | +// Template for "build" CLI handling ends here |
| 119 | + |
| 120 | +// Template for "install" CLI handling starts here |
| 121 | +//////////////////////////////////////////////////////////////////////////// |
| 122 | +// Program: redo |
| 123 | +// Purpose: global option redo |
| 124 | +// Authors: Myself < [email protected]> (c) 2022, All rights reserved |
| 125 | +//////////////////////////////////////////////////////////////////////////// |
| 126 | + |
| 127 | +// package main |
| 128 | + |
| 129 | +// import ( |
| 130 | +// "fmt" |
| 131 | +// "os" |
| 132 | +// ) |
| 133 | + |
| 134 | +// *** Sub-command: install *** |
| 135 | + |
| 136 | +//////////////////////////////////////////////////////////////////////////// |
| 137 | +// Constant and data type/structure definitions |
| 138 | + |
| 139 | +// The InstallCommand type defines all the configurable options from cli. |
| 140 | +// type InstallCommand struct { |
| 141 | +// Dir string `short:"d description:"source code root dir" default:"./"` |
| 142 | +// Suffix string `long:"suffix" description:"source file suffix" default:".go,.c,.s"` |
| 143 | +// } |
| 144 | + |
| 145 | +// |
| 146 | +// var installCommand InstallCommand |
| 147 | +// |
| 148 | +// InstallCommand implements the business logic of command `install` |
| 149 | +// func (x *InstallCommand) Execute(args []string) error { |
| 150 | +// fmt.Fprintf(os.Stderr, "Install the network application\n") |
| 151 | +// // fmt.Fprintf(os.Stderr, "Copyright (C) 2022, Myself < [email protected]>\n\n") |
| 152 | +// // fmt.Printf("Doing Install, with %#v\n", args) |
| 153 | +// // fmt.Println(x.Dir, x.Suffix) |
| 154 | +// // err := ... |
| 155 | +// return nil |
| 156 | +// } |
| 157 | +// |
| 158 | +// func init() { |
| 159 | +// parser.AddCommand("install", |
| 160 | +// "Install the network application", |
| 161 | +// "The add command adds a file to the repository. Use -a to add all files", |
| 162 | +// &installCommand) |
| 163 | +// } |
| 164 | +// Template for "install" CLI handling ends here |
| 165 | + |
| 166 | +// Template for "publish" CLI handling starts here |
| 167 | +//////////////////////////////////////////////////////////////////////////// |
| 168 | +// Program: redo |
| 169 | +// Purpose: global option redo |
| 170 | +// Authors: Myself < [email protected]> (c) 2022, All rights reserved |
| 171 | +//////////////////////////////////////////////////////////////////////////// |
| 172 | + |
| 173 | +// package main |
| 174 | + |
| 175 | +// import ( |
| 176 | +// "fmt" |
| 177 | +// "os" |
| 178 | +// ) |
| 179 | + |
| 180 | +// *** Sub-command: publish *** |
| 181 | + |
| 182 | +//////////////////////////////////////////////////////////////////////////// |
| 183 | +// Constant and data type/structure definitions |
| 184 | + |
| 185 | +// The PublishCommand type defines all the configurable options from cli. |
| 186 | +// type PublishCommand struct { |
| 187 | +// Dir string `short:"d" long:"dir" description:"publish dir" required:"true"` |
| 188 | +// Suffix string `long:"suffix" description:"source file suffix" default:".go,.c,.s"` |
| 189 | +// Out string `short:"o" long:"out" description:"output filename"` |
| 190 | +// |
| 191 | +// // Example of positional arguments |
| 192 | +// Args struct { |
| 193 | +// ID string |
| 194 | +// Num int |
| 195 | +// Rest []string |
| 196 | +// } `positional-args:"yes" required:"yes"` |
| 197 | + |
| 198 | +// } |
| 199 | + |
| 200 | +// |
| 201 | +// var publishCommand PublishCommand |
| 202 | +// |
| 203 | +// PublishCommand implements the business logic of command `publish` |
| 204 | +// func (x *PublishCommand) Execute(args []string) error { |
| 205 | +// fmt.Fprintf(os.Stderr, "Publish the network application\n") |
| 206 | +// // fmt.Fprintf(os.Stderr, "Copyright (C) 2022, Myself < [email protected]>\n\n") |
| 207 | +// // fmt.Printf("Doing Publish, with %#v\n", args) |
| 208 | +// // fmt.Println(x.Dir, x.Suffix, x.Out, x.Args) |
| 209 | +// // err := ... |
| 210 | +// return nil |
| 211 | +// } |
| 212 | +// |
| 213 | +// func init() { |
| 214 | +// parser.AddCommand("publish", |
| 215 | +// "Publish the network application", |
| 216 | +// "Publish the built network application to central repo", |
| 217 | +// &publishCommand) |
| 218 | +// } |
| 219 | +// Template for "publish" CLI handling ends here |
| 220 | + |
| 221 | + |
0 commit comments