cmd

package
v0.0.0-...-d10ae67 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConvertCmd = &cobra.Command{
	Use:     "convert",
	Aliases: []string{"c"},
	Short:   "convert prestashop-shop-creator xml to golang structs.",
	Long:    "convert prestashop-shop-creator xml to golang structs",
	Run: func(cmd *cobra.Command, args []string) {

		err := godirwalk.Walk(workDir, &godirwalk.Options{
			Callback: func(osPathname string, de *godirwalk.Dirent) error {
				if !de.IsDir() {

					extension := filepath.Ext(osPathname)
					filename := path.Base(osPathname)
					pkgName := strings.Replace(filename, extension, "", -1)
					if extension == ".xml" {
						if options.verbose {
							log.Println("found ", osPathname, "extension", extension)
						}

						file, err := os.Open(osPathname)
						if err != nil {
							return err
						}

						root := new(zek.Node)
						root.MaxExamples = maxExamples

						reader := bufio.NewReader(file)
						if _, err := root.ReadFrom(reader); err != nil {
							log.Warnf("could not read '%s', error: %s", osPathname, err)
							return err
						}

						if tagName != "" {
							if n := root.ByName(tagName); n != nil {
								root = n
							}
						}
						root.Name = xml.Name{Space: "", Local: pkgName}

						var buf bytes.Buffer
						io.WriteString(&buf, tmplPackage)
						sw := zek.NewStructWriter(&buf)
						sw.WithComments = withComments
						sw.WithJSONTags = withJSONTags
						sw.Strict = strict
						sw.ExampleMaxChars = exampleMaxChars
						sw.Compact = !nonCompact
						sw.UniqueExamples = uniqueExamples
						sw.OmitEmptyText = omitEmptyText
						if err := sw.WriteNode(root); err != nil {
							log.Fatal(err)
						}

						f, err := os.Create(filepath.Join(outputDir, fmt.Sprintf("%s.go", pkgName)))
						if err != nil {
							log.Fatal(err)
						}
						defer f.Close()

						if !skipFormatting {
							b, err := format.Source(buf.Bytes())
							if err != nil {
								log.Fatal(err)
							}
							_, err = f.Write(b)
							if err != nil {
								log.Fatal(err)
							}
						} else {
							_, err := f.WriteString(buf.String())
							if err != nil {
								log.Fatal(err)
							}
						}

					}
				}
				return nil
			},
			Unsorted: true,
		})
		checkErr("Dir walk, error", err)

	},
}
View Source
var RootCmd = &cobra.Command{
	Use:   "fixture2struct",
	Short: "fixture2struct is an helper to convert prestashop-shop-creator xml files into go structs",
	Long:  `fixture2struct is an helper to convert prestashop-shop-creator xml files into go structs`,
}

RootCmd is the root command for ovh-qa

Functions

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately.

Types

This section is empty.

Jump to

Keyboard shortcuts

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