github.com/beauknowssoftware/makehcl@v0.0.0-20200322000747-1b9bb1e1c008/internal/cmd/targets.go (about)

     1  package cmd
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  
     7  	"github.com/beauknowssoftware/makehcl/internal/targets"
     8  	"github.com/jessevdk/go-flags"
     9  )
    10  
    11  type TargetsCommand struct {
    12  	Filename    flags.Filename `short:"f" long:"filename"`
    13  	Sort        bool           `short:"s" long:"sort"`
    14  	RuleOnly    bool           `short:"r" long:"rule-only"`
    15  	CommandOnly bool           `short:"c" long:"command-only"`
    16  }
    17  
    18  func (c *TargetsCommand) Execute(_ []string) error {
    19  	if c.RuleOnly && c.CommandOnly {
    20  		return errors.New("cannot specify rule only and command only at the same time")
    21  	}
    22  
    23  	var o targets.DoOptions
    24  	o.Filename = string(c.Filename)
    25  	o.Sort = c.Sort
    26  	o.RuleOnly = c.RuleOnly
    27  	o.CommandOnly = c.CommandOnly
    28  
    29  	ts, err := targets.Do(o)
    30  	if err != nil {
    31  		return err
    32  	}
    33  
    34  	for _, t := range ts {
    35  		fmt.Println(t)
    36  	}
    37  
    38  	return nil
    39  }