Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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()
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
You can’t perform that action at this time.