cloudfoundry / bosh-cli

BOSH CLI v2+
Apache License 2.0
178 stars 162 forks source link

Hide completion from main #655

Closed aramprice closed 4 months ago

aramprice commented 4 months ago

The conditional here for the Completion UI should be pushed down into factory.New()

main.go:22

func main() {
    logger := newLogger()
    defer handlePanic()

    ui := boshui.NewConfUI(logger)
    defer ui.Flush()

    if completion.IsItCompletionCommand(os.Args[1:]) {
        // completion support
        blindUi := boshui.NewWrappingConfUI(&completion.BlindUI{}, logger) // only completion can write to stdout
        bc := completion.NewBoshComplete(blindUi, logger)

        err := bc.Execute(os.Args[1:])
        if err != nil {
            fail(err, ui, logger)
        }
    } else {
        cmdFactory := boshcmd.NewFactory(boshcmd.NewBasicDeps(ui, logger))

        cmd, err := cmdFactory.New(os.Args[1:])
        if err != nil {
            fail(err, ui, logger)
        }

        err = cmd.Execute()
        if err != nil {
            fail(err, ui, logger)
        } else {
            success(ui, logger)
        }
    }
}