package main

import (
	
	
	

	
	

	
	amhelp 
	am 
)

var ss = states.CliStates

type Args struct {
	Foo1     bool          `arg:"--foo-1" help:"Foo help"`
	Bar2     bool          `arg:"--bar-2" help:"Bar help"`
	Duration time.Duration `arg:"-d,--duration" default:"3s" help:"Duration of the demo"`
	Debug    bool          `default:"true" help:"Enable debugging for asyncmachine"`
}

type cli struct {
	*am.ExceptionHandler

	Mach *am.Machine
	Args *Args
}

var args Args

func main() {
	 := arg.MustParse(&args)
	 := context.Background()
	,  := newCli(, &args)
	if  != nil {
		panic()
	}

	if args.Foo1 {
		.Mach.Add1(ss.Foo1, nil)
	} else if args.Bar2 {
		.Mach.Add1(ss.Bar2, nil)
	} else {
		.Fail("no flag")
	}

	<-.Mach.WhenNot1(ss.Start, nil)
}

// newCli creates a new CLI with a state machine.
func newCli( context.Context,  *Args) (*cli, error) {
	if .Debug {
		fmt.Printf("debugging enabled\n")
		// load .env
		_ = godotenv.Load()
	}

	 := &cli{
		Args: ,
	}
	,  := am.NewCommon(, "cli", states.CliSchema, ss.Names(),
		, nil, &am.Opts{
			DontPanicToException: .Debug,
		})
	if  != nil {
		return nil, 
	}
	if .Debug {
		amhelp.MachDebugEnv()
	}
	.Mach = 

	return , nil
}

func ( *cli) ( *am.Event) {
	 := .Mach.NewStateCtx(ss.Start)
	fmt.Printf("starting for %s\n", .Transition().CalledStates())
	go func() {
		select {
		case <-.Done():
		case <-time.After(.Args.Duration):
		}
		fmt.Printf("start done\n")
		.Mach.Remove1(ss.Start, nil)
	}()
}