Skip to content

Commit 71be01c

Browse files
committed
- [+] std flag based project wireframe initiated
1 parent 70ef318 commit 71be01c

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed

OpenSesame_cli.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# program name, name for the executable
2+
ProgramName: OpenSesame
3+
4+
PackageName: main
5+
6+
# Name of the structure to hold the values for/from commandline
7+
StructName: Options
8+
# The actual variable that hold the commandline paramter values
9+
StructVar: Opts
10+
11+
# Whether to use the USAGE_SUMMARY in Usage help
12+
UsageSummary: ""
13+
14+
UsageLead: "\\nUsage:\\n %s [flags..]\\n\\nFlags:\\n\\n"
15+
16+
UsageEnd: "\\n"
17+
18+
Options:
19+
20+
- Name: Port
21+
Type: string
22+
Flag: port
23+
Usage: listening port
24+
Value: '"18888"'
25+
26+
- Name: Path
27+
Type: string
28+
Flag: path
29+
Usage: path to serve files from
30+
Value: '"./"'
31+

OpenSesame_cliDef.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// !!! !!!
2+
// WARNING: Code automatically generated. Editing discouraged.
3+
// !!! !!!
4+
5+
package main
6+
7+
import (
8+
"flag"
9+
"fmt"
10+
"os"
11+
)
12+
13+
////////////////////////////////////////////////////////////////////////////
14+
// Constant and data type/structure definitions
15+
16+
const progname = "OpenSesame" // os.Args[0]
17+
18+
// The Options struct defines the structure to hold the commandline values
19+
type Options struct {
20+
Port string // listening port
21+
Path string // path to serve files from
22+
}
23+
24+
////////////////////////////////////////////////////////////////////////////
25+
// Global variables definitions
26+
27+
// Opts holds the actual values from the command line parameters
28+
var Opts Options
29+
30+
////////////////////////////////////////////////////////////////////////////
31+
// Commandline definitions
32+
33+
func init() {
34+
35+
// set default values for command line parameters
36+
flag.StringVar(&Opts.Port, "port", "18888",
37+
"listening port")
38+
flag.StringVar(&Opts.Path, "path", "./",
39+
"path to serve files from")
40+
41+
// Now override those default values from environment variables
42+
if len(Opts.Port) == 0 ||
43+
len(os.Getenv("OPENSESAME_PORT")) != 0 {
44+
Opts.Port = os.Getenv("OPENSESAME_PORT")
45+
}
46+
if len(Opts.Path) == 0 ||
47+
len(os.Getenv("OPENSESAME_PATH")) != 0 {
48+
Opts.Path = os.Getenv("OPENSESAME_PATH")
49+
}
50+
51+
}
52+
53+
// Usage function shows help on commandline usage
54+
func Usage() {
55+
fmt.Fprintf(os.Stderr,
56+
"\nUsage:\n %s [flags..]\n\nFlags:\n\n",
57+
progname)
58+
flag.PrintDefaults()
59+
fmt.Fprintf(os.Stderr,
60+
"\n")
61+
os.Exit(0)
62+
}

OpenSesame_cliGen.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
templateFile=$GOPATH/src/github.com/go-easygen/easygen/test/commandlineFlag
2+
[ -s $templateFile.tmpl ] || templateFile=/usr/share/gocode/src/github.com/go-easygen/easygen/test/commandlineFlag
3+
[ -s $templateFile.tmpl ] || templateFile=/usr/share/doc/easygen/examples/commandlineFlag
4+
[ -s $templateFile.tmpl ] || {
5+
echo No template file found
6+
exit 1
7+
}
8+
9+
easygen $templateFile OpenSesame_cli | gofmt > OpenSesame_cliDef.go

0 commit comments

Comments
 (0)