Created
May 13, 2020 08:54
-
-
Save podhmo/d9860397e7538086a24d08de18f73e00 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from egoist.app import App, SettingsDict | |
settings: SettingsDict = {"rootdir": "cmd/", "here": __file__} | |
app = App(settings) | |
app.include("egoist.directives.define_cli") | |
@app.define_cli("egoist.generators.clikit:walk") | |
def hello(*, name: str, age: int = 20, who: str = "foo") -> None: | |
"""hello message""" | |
from egoist.generators.clikit import runtime, clikit | |
options = runtime.get_cli_options() | |
options.name.help = "the name of target person" | |
options.age.help = "age of subject" | |
options.who.help = "name of subject" | |
with runtime.generate(clikit) as m: | |
hello_pkg = m.import_("m/internal/hello") | |
m.stmt(hello_pkg.Hello(name, age, who)) # m.stmtを忘れずに | |
if __name__ == "__main__": | |
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module m | |
go 1.14 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package hello | |
import "fmt" | |
// Hello ... | |
func Hello(name string, age int, who string) { | |
fmt.Printf("%s(%d): hello %s\n", who, age, name) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"fmt" | |
"os" | |
"log" | |
"m/internal/hello" | |
) | |
// this file is generated by egoist.generators.clikit | |
// Option ... | |
type Option struct { | |
Name string // for `-name` | |
Age int // for `-age` | |
Who string // for `-who` | |
Args []string // cmd.Args | |
} | |
func main() { | |
opt := &Option{} | |
cmd := flag.NewFlagSet("hello", flag.ContinueOnError) | |
cmd.Usage = func() { | |
fmt.Fprintln(cmd.Output(), `hello - hello message`) | |
fmt.Fprintln(cmd.Output(), "") | |
fmt.Fprintln(cmd.Output(), "Usage:") | |
cmd.PrintDefaults() | |
} | |
cmd.StringVar(&opt.Name, "name", "", "the name of target person") | |
cmd.IntVar(&opt.Age, "age", 20, "age of subject") | |
cmd.StringVar(&opt.Who, "who", "foo", "name of subject") | |
if err := cmd.Parse(os.Args[1:]); err != nil { | |
if err != flag.ErrHelp { | |
cmd.Usage() | |
} | |
os.Exit(1) | |
} | |
opt.Args = cmd.Args() | |
if err := run(opt); err != nil { | |
log.Fatalf("!!%+v", err) | |
} | |
} | |
func run(opt *Option) error { | |
hello.Hello(opt.Name, opt.Age, opt.Who) | |
return nil | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gen: | |
python definitions.py generate | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
. | |
├── Makefile | |
├── cmd | |
│ └── hello | |
│ └── main.go | |
├── definitions.py | |
├── go.mod | |
├── internal | |
│ └── hello | |
│ └── hello.go | |
└── structure.txt | |
4 directories, 6 files |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment