Skip to content
Snippets Groups Projects
Select Git revision
  • fa3465e68c81e99d2697c2b8d5dc0de9dba57821
  • master default protected
  • v1.16.5
  • v1.16.4
  • v1.16.3
  • v1.16.2
  • v1.16.1
  • v1.16.0
  • v1.15.0
  • v1.14.0
  • v1.13.2
  • v1.13.1
  • v1.13.0
  • v1.12.0
  • v1.11.0
  • v1.10.2
  • v1.10.1
  • v1.10.0
  • v1.9.0
  • v1.8.3
  • v1.8.2
  • v1.8.1
22 results

flag_test.go

Blame
  • flag_test.go 935 B
    // 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())
    }