Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var AppendCmd = &cobra.Command{ Use: "append <query> <newValue>", Short: "append value(s) to a list or a string", Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { newValue := args[1] return setImpl(cmd, args[0], func(list *ast.ListType) error { node, err := getValueFromJSON(newValue) if err != nil { return err } list.List = append(list.List, node) return nil }, func(tok *token.Token) error { tok.Text = `"` + trimToken(tok.Text) + newValue + `"` tok.Type = token.STRING return nil }) }, }
AppendCmd cobra command
View Source
var GetCmd = &cobra.Command{ Use: "get <query>", Short: "retrieve values matching <query>", RunE: func(cmd *cobra.Command, args []string) error { qry, _ := query.Parse(args[0]) reader := os.Stdin if val := inFile; val != "" { var err error reader, err = os.Open(val) if err != nil { return err } } raw := cmd.Flag("raw").Value.String() == "true" resultPairs, isList, _, err := query.HCL(reader, qry) results := []interface{}{} for _, pair := range resultPairs.Values { results = append(results, pair) } if !isList && len(results) == 1 { output, err := getOutput(results[0], raw) if err != nil { return err } fmt.Print(output) return err } output, err := getOutput(results, raw) if err != nil { return err } output = strings.Trim(output, " \n") fmt.Print(output) return err }, }
GetCmd command
View Source
var PrependCmd = &cobra.Command{ Use: "prepend <query> <newValue>", Short: "prepend value(s) to a list or a string", Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { newValue := args[1] return setImpl(cmd, args[0], func(list *ast.ListType) error { node, err := getValueFromJSON(newValue) if err != nil { return err } list.List = append(node.(*ast.ListType).List, list.List...) return nil }, func(tok *token.Token) error { tok.Text = `"` + newValue + trimToken(tok.Text) + `"` tok.Type = token.STRING return nil }) }, }
PrependCmd cobra command
View Source
var ReplaceCmd = &cobra.Command{ Use: "replace <query> <oldSequence> <newSequence>", Short: "find and replace a subsequence of items (or chars for strings)", Args: cobra.ExactArgs(3), RunE: func(cmd *cobra.Command, args []string) error { return setImpl(cmd, args[0], func(list *ast.ListType) error { panic("Not implemented") }, func(tok *token.Token) error { tok.Text = `"` + strings.Replace(trimToken(tok.Text), args[1], args[2], replaceN) + `"` tok.Type = token.STRING return nil }) }, }
ReplaceCmd cobra command
View Source
var RootCmd = &cobra.Command{
Use: "hclq [flags] [command]",
Version: version,
Short: "Query and modify HashiCorp HCL files",
Long: `hclq is a tool for querying the values of HCL files, reminiscent of jq.
Queries can return either single or multiple values, which means that hclq commands work over ALL results of a query.
This means that commands such as set can work over many keys at once.
hclq outputs JSON by default. A tool such as jq is recommended for further processing.`,
}
RootCmd command
View Source
var RootFlags = RootCmd.PersistentFlags()
RootFlags flags
View Source
var SetCmd = &cobra.Command{ Use: "set <query> <newValue>", Short: "set matching value(s), specify a string, number, or JSON object or array", Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { newValue := args[1] return setImpl(cmd, args[0], func(list *ast.ListType) error { hcl, err := getValueFromJSON(newValue) if err != nil { return err } list.List = hcl.(*ast.ListType).List return nil }, func(tok *token.Token) error { tok.Text = `"` + newValue + `"` tok.Type = getTokenType(newValue) return nil }) }, }
SetCmd cobra command
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.