gen.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. Copyright © 2023 NAME HERE <EMAIL ADDRESS>
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package cmd
  14. import (
  15. "git.capella.pro/ipredirect/grammar"
  16. "github.com/sirupsen/logrus"
  17. "github.com/spf13/cobra"
  18. )
  19. // genCmd represents the gen command
  20. var genCmd = &cobra.Command{
  21. Use: "gen",
  22. Short: "A brief description of your command",
  23. Long: `A longer description that spans multiple lines and likely contains examples
  24. and usage of using your command. For example:
  25. Cobra is a CLI library for Go that empowers applications.
  26. This application is a tool to generate the needed files
  27. to quickly create a Cobra application.`,
  28. Run: func(cmd *cobra.Command, args []string) {
  29. gencode()
  30. },
  31. }
  32. func init() {
  33. rootCmd.AddCommand(genCmd)
  34. // Here you will define your flags and configuration settings.
  35. // Cobra supports Persistent Flags which will work for this command
  36. // and all subcommands, e.g.:
  37. // genCmd.PersistentFlags().String("foo", "", "A help for foo")
  38. // Cobra supports local flags which will only run when this command
  39. // is called directly, e.g.:
  40. // genCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
  41. }
  42. func gencode() {
  43. pgot, err := grammar.ParseFile("README", grammar.Recover(false), grammar.Entrypoint("Input"))
  44. if err != nil {
  45. logrus.Panic(err)
  46. }
  47. logrus.Info(pgot)
  48. }