"log"
	"os"

	"github.com/logrusorgru/aurora/v3"
	"github.com/mattn/go-colorable"
	"github.com/mattn/go-isatty"
	"github.com/spf13/cobra"
)

var (
	rootCmd = &cobra.Command{
		Use:   "vespa command-name",
		Short: "The command-line tool for Vespa.ai",
		Long: `The command-line tool for Vespa.ai.

Use it on Vespa instances running locally, remotely or in the cloud.
Prefer web service API's to this in production.

Vespa documentation: https://docs.vespa.ai`,
		DisableAutoGenTag: true,
		PersistentPreRun: func(cmd *cobra.Command, args []string) {
			configureOutput()
		},
	}

	targetArg      string
	applicationArg string
	waitSecsArg    int
	colorArg       string
	quietArg       bool
	stdin          io.ReadWriter = os.Stdin

	color  = aurora.NewAurora(false)
	stdout = colorable.NewColorableStdout()
	stderr = colorable.NewColorableStderr()
)

const (
	applicationFlag = "application"
	targetFlag      = "target"
	waitFlag        = "wait"
	colorFlag       = "color"
	quietFlag       = "quiet"
	cloudAuthFlag   = "cloudAuth"
)

func isTerminal() bool {
	if f, ok := stdout.(*os.File); ok {
		return isatty.IsTerminal(f.Fd())
	}
	if f, ok := stderr.(*os.File); ok {
		return isatty.IsTerminal(f.Fd())
	}
	return false
}

func configureOutput() {
	if quietArg {
		stdout = ioutil.Discard
	}
	log.SetFlags(0) // No timestamps
	log.SetOutput(stdout)

	config, err := LoadConfig()
	if err!= nil {
		fatalErr(err, "Could not load config")
	}
	colorValue, err := config.Get(colorFlag)
	if err!= nil {
		fatalErr(err)
	}

	colorize := false
	switch colorValue {
	case "auto":
		colorize = isTerminal()
	case "always":
		colorize = true
	case "never":
	default:
		fatalErrHint(fmt.Errorf("Invalid value for %s option", colorFlag), "Must be \"auto\", \"never\" or \"always\"")
	}
	color = aurora.NewAurora(colorize)
}

func init() {
	rootCmd.PersistentFlags().StringVarP(&targetArg, targetFlag, "t", "local", "The name or URL of the recipient of this command")
	rootCmd.PersistentFlags().StringVarP(&applicationArg, applicationFlag, "a", "", "The application to manage")
	rootCmd.PersistentFlags().IntVarP(&waitSecsArg, waitFlag, "w", 0, "Number of seconds to wait for a service to become ready")
	rootCmd.PersistentFlags().StringVarP(&colorArg, colorFlag, "c", "auto", "Whether to use colors in output. Can be \"auto\", \"never\" or \"always\"")
	rootCmd.PersistentFlags().BoolVarP(&quietArg, quietFlag, "q", false, "Quiet mode. Only errors are printed.")
	bindFlagToConfig(targetFlag, rootCmd)
	bindFlagToConfig(applicationFlag, rootCmd)
	bindFlagToConfig(waitFlag, rootCmd)
	bindFlagToConfig(colorFlag, rootCmd)
	bindFlagToConfig(quietFlag, rootCmd)
}

// Execute executes the root command.
func Execute() error { return rootCmd.Execute() }
extract it in a folder. Alternately look at man pages of tar command.
tar.xz by heart but there should be.
>   "There was a problem opening the file /home/vishal/vlc-2.0.5.tar.xz."
> editing this file you could corrupt        this document"
>   "You can also choose another character encoding and try again"
> help me in compiling of the source code.Félix Stüssi performed on piano accompanied by a five piece band at the Upstairs Jazz Bar in Montreal this past August, 2008. This performance was a CD launch for his second CD, Baiji (Justin Time, 2008). Félix Stüssi, the Swiss-born Montreal-based musician, is on a roll. Last year he won the coveted GM prize at the 2007 Montreal Jazz Festival with his first CD, Give Me Five (LOCAL/Outside Music, 2007). Now, just a year later with his new CD, Baiji, there are sure to be more festivals and prizes in Félix Stüssi's future.
The CD launch started out with a blues called "Yann, the Boogieman." In his introduction Felix explained that it's "for my son Yann who I hope is not being a Boogieman with the babysitter." This was followed by, "Give Me Five," the title track of Felix's first CD. The third song, "Primavera," was the first offering from the new work. Felix described this piece as "what happens after a long winter here in the province of Quebec." This piece starts with a drum solo by the imaginative Isaiah Ceccarelli. The drum solo has a snowy winter feeling and is followed by a drum roll which brings in the band. The piece has an upbeat swing feel highlighting the skills of Bruno Lamarche on tenor sax and Alex Côté on alto sax. Felix's piano solo in "Primavera" hints at snow changing into spring rain.
Next was "Bénéfisch," a soft ballad that opens with a beautiful bass solo by Clinton Ryder. During the bass solo a waltz time is established when the brushes come in followed by the rest of the band. "On the Verge," again from the new album, features Alex on alto sax. During this piece a well known jazz journalist leaned over and said, "Doesn't that sound like an Ellington tune?" This piece was freer than the previous ones and the bass was running, not walking, at a fevered pitch. Isaiah and Clinton were almost burning a hole in the floor with their energy. The audience tapped their toes as the band swung hard.
The second set included guest trombonist, Jean Nicolas Trottier, and opened with the song "Baiji," the title track from the new CD. The third song was "Porc-épic" (French for porcupine), starting with a piano solo that becomes a blues and then gets free again, ending with trombone and drums. Isaiah uses bells, chopsticks and little metal rods. He appears to have three arms. Felix explained after the set that he asked Isaiah to play "spiky." Felix gives musicians lots of freedom, and his band's solos are all improvised and undirected. Felix thinks of colors when he composes.
Felix ended the second set with "Friifad," a piece inspired by his time as a goat herder in the Swiss Alps. Appropriately the music starts with herding bells, alto sax, and bass, making goat horn sound. Bruno's clarinet is way out and free. Jean Nicolas and the band work well together, and you can see they have invested a lot of time and energy into this project. This evening's concert was sold out, and rightly so; Felix and his band have been working together since 2004, and if this latest CD is any indication of what is to come, there will be many more sold out shows.
On the CD Baiji, American trombone legend Ray Anderson is featured and will be touring with Felix's band in 2009.
All About Jazz: What piano greats inspire you?
Félix Stüssi: The black players, mostly artists like Bud Powell, Art Tatum, Sonny Clark, Barry Harris. I guess they are more traditional, and of course among the modern players, Herbie Hancock, Keith Jarrett. I am influenced a lot by the blues—Muddy Waters, Otis Spann and New Orleans musicians like James Booker.
AAJ: Do you have some important teachers you took master classes with?
FS: I took master classes with several pianists, including Fred Hersch, but there were two musicians that had a major influence on my musical career: Irène Schweizer, a famous European free jazz pioneer who has opened my mind to new worlds, and secondly, Vince Benedetti who recorded for Blue Note in the sixties with Hank Mobley and Philly Joe Jones. Benedetti has deepened my knowledge of the jazz tradition.
AAJ: Tell me about the creation of your CD Give Me Five.
FS: Give Me Five was