list

package
v0.0.19 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ListCmd = &cobra.Command{
	Use:   "list",
	Short: "A brief description of your command",
	Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:

Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
	PreRunE: func(cmd *cobra.Command, args []string) error {
		if len(args) > 0 {
			return utils.ErrTooManyArgs
		}

		return nil
	},
	RunE: func(cmd *cobra.Command, args []string) error {
		logger := cmd.Context().Value(constants.LoggerKey{}).(zerolog.Logger)
		socketPath := cmd.Context().Value(constants.SocketPathKey{}).(string)

		logger.Info().
			Str("operation", cmd.Name()).
			Msg(constants.ProcessCommand)

		res, err := utils.SendCommandToDaemon(socketPath, cmd.Name())
		if err != nil {
			logger.Error().Str("command", cmd.Name()).Err(err).Msg(constants.FailedToProcessCommand)

			return &utils.CommandError{Err: err, Code: 10}
		}

		logger.Info().Str("command", cmd.Name()).Msg(constants.SuccessfullyProcessed)

		domains, err := state.FromStringSlice(res)
		if err != nil {
			logger.Error().Err(err).Msg("failed to parse response")

			return &utils.CommandError{Err: err, Code: 11}
		}

		table := tablewriter.NewWriter(os.Stdout)
		table.SetHeader([]string{"Domain", "Gateway", "IPs"})

		table.SetColumnAlignment([]int{tablewriter.ALIGN_CENTER, tablewriter.ALIGN_CENTER, tablewriter.ALIGN_CENTER})
		table.SetBorder(true)
		table.SetRowLine(true)
		table.SetAlignment(tablewriter.ALIGN_CENTER)

		for _, info := range domains {
			table.Append([]string{info.Domain, info.Gateway, strings.Join(info.ResolvedIPs, "\n")})
		}

		table.Render()

		return nil
	},
}

ListCmd represents the list command

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL