package main

import (
	"fmt"
	"os"

	"github.com/spf13/cobra"
	"github.com/spf13/viper"

	"omixlab.com/mosis-portal/cmd/mosis/cmd"
)

func main() {
	rootCmd := &cobra.Command{
		Use:   "mosis",
		Short: "Mosis app development CLI",
		Long:  "CLI tool for building, signing, and publishing Mosis apps",
	}

	// Global flags
	rootCmd.PersistentFlags().StringP("portal", "p", "", "Portal URL")
	rootCmd.PersistentFlags().BoolP("verbose", "v", false, "Verbose output")

	viper.BindPFlag("portal_url", rootCmd.PersistentFlags().Lookup("portal"))
	viper.BindPFlag("verbose", rootCmd.PersistentFlags().Lookup("verbose"))

	// Initialize config
	cmd.InitConfig()

	// Add commands
	rootCmd.AddCommand(cmd.InitCmd())
	rootCmd.AddCommand(cmd.ValidateCmd())
	rootCmd.AddCommand(cmd.BuildCmd())
	rootCmd.AddCommand(cmd.SignCmd())
	rootCmd.AddCommand(cmd.RunCmd())
	rootCmd.AddCommand(cmd.LoginCmd())
	rootCmd.AddCommand(cmd.LogoutCmd())
	rootCmd.AddCommand(cmd.PublishCmd())
	rootCmd.AddCommand(cmd.StatusCmd())
	rootCmd.AddCommand(cmd.KeysCmd())
	rootCmd.AddCommand(cmd.ConfigCmd())

	if err := rootCmd.Execute(); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
}
