Created
May 13, 2020 09:31
-
-
Save podhmo/076cff15ff0c6fbd4c389d0fa8a128b1 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) -> None: | |
"""hello message""" | |
from egoist.generators.clikit import runtime, clikit | |
with runtime.generate(clikit): | |
runtime.printf("hello %s\n", name) | |
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
package main | |
import ( | |
"flag" | |
"fmt" | |
"os" | |
"log" | |
) | |
// this file is generated by egoist.generators.clikit | |
// Option ... | |
type Option struct { | |
Name string // for `-name` | |
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", "", "-") | |
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 { | |
fmt.Printf("hello %s\n", opt.Name) | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment