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

     1  package cmd
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"github.com/beauknowssoftware/makehcl/internal/graph"
     8  	"github.com/jessevdk/go-flags"
     9  )
    10  
    11  type graphType graph.Type
    12  
    13  func (t *graphType) Complete(match string) (result []flags.Completion) {
    14  	var options = []graph.Type{
    15  		graph.ImportGraph,
    16  	}
    17  
    18  	for _, o := range options {
    19  		if strings.HasPrefix(string(o), match) {
    20  			result = append(result, flags.Completion{
    21  				Item: string(o),
    22  			})
    23  		}
    24  	}
    25  
    26  	return
    27  }
    28  
    29  type GraphCommand struct {
    30  	GraphType          graphType      `short:"g" long:"graph-type" required:"true"`
    31  	Filename           flags.Filename `short:"f" long:"filename"`
    32  	IgnoreParserErrors bool           `short:"i" long:"ignore-parser-errors"`
    33  }
    34  
    35  func (c *GraphCommand) Execute(_ []string) error {
    36  	var o graph.DoOptions
    37  	o.Filename = string(c.Filename)
    38  	o.IgnoreParserErrors = c.IgnoreParserErrors
    39  	o.GraphType = graph.Type(c.GraphType)
    40  
    41  	g, diag, err := graph.Do(o)
    42  
    43  	if diag.HasErrors() {
    44  		return diag
    45  	}
    46  
    47  	if err != nil {
    48  		return err
    49  	}
    50  
    51  	fmt.Println(g)
    52  
    53  	return nil
    54  }