cmd

package
v0.0.0-...-25fd724 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MainCommand = &cobra.Command{
	Use:  "avro-generator",
	Args: cobra.ExactArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		if *f.outputFile == "." {
			*f.outputFile = fmt.Sprintf("%s.avsc", args[0])
		}
		sourceTypePackage := *f.pkg
		sourceTypeName := args[0]

		pkg, err := loadPackage(sourceTypePackage)
		if err != nil {
			return err
		}

		obj := pkg.Types.Scope().Lookup(sourceTypeName)
		if obj == nil {
			return fmt.Errorf("%s not found in declared types of %s",
				sourceTypeName, pkg)
		}

		if _, ok := obj.(*types.TypeName); !ok {
			return fmt.Errorf("%v is not a named type", obj)
		}

		err = ioutil.WriteFile(*f.outputFile, []byte(avrotypes.ASTNodeToAvro(obj.Name(), obj.Type().Underlying())), os.ModePerm)
		return err
	},
}

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