// Copyright 2022 schukai GmbH
// SPDX-License-Identifier: AGPL-3.0-or-later

package xflags

import (
	"fmt"
	"github.com/stretchr/testify/assert"
	"testing"
)

func TestWrongDefinitionType(t *testing.T) {
	c := New("root", 2)
	c.Parse([]string{"test"})
	c.Execute()
	assert.True(t, c.HasErrors())
}

type testExecuteCommandStruct struct {
	Command1 struct {
	} `command:"command1" description:"Command 1" callback:"command1Callback" `
	Command2 struct {
		Command3 struct {
		} `command:"command3" description:"Command 3" callback:"command3Callback" `
	} `command:"command2" description:"Command 2" callback:"command2Callback" `
}

func (c *testExecuteCommandStruct) command1Callback(args []string) {
	fmt.Println("command1Callback", args)
}

func TestExecute1(t *testing.T) {
	c := New("root", testExecuteCommandStruct{})
	c.Parse([]string{"root", "command2", "command3", "commandX"})
	c.Execute()
	assert.False(t, c.HasErrors())
}