Newer
Older
httpcat / src / main.go
/**
  Author: Mark George <mark.george@otago.ac.nz>
  License: Zero-Clause BSD License: https://opensource.org/license/0bsd/
*/

package main

import (
	"fmt"
	"os"

	"github.com/jessevdk/go-flags"
)

const version string = "2.4"

type VersionCommand struct{}

func (c *VersionCommand) Execute(args []string) error {
	fmt.Println("httpcat v" + version)
	return nil
}

func main() {
	parser := flags.NewParser(globalOptions, flags.Default)

	parser.AddCommand("client", "Send an HTTP request", "", &ClientCommand{})
	parser.AddCommand("server", "Start a mock HTTP server", "", &ServerCommand{})
	parser.AddCommand("proxy", "Start a reverse HTTP logging proxy", "", &ProxyCommand{})
	parser.AddCommand("version", "Display version", "", &VersionCommand{})

	_, err := parser.Parse()
	if err != nil {
		parseErr := err.(*flags.Error)

		if parseErr.Type.String() == flags.ErrCommandRequired.String() {
			os.Stderr.WriteString("\n")
			parser.WriteHelp(os.Stderr)
		}
	}
}