command

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var InitCmd = &cobra.Command{
	Use:   "init",
	Short: "init project",
	Run: func(cmd *cobra.Command, arg []string) {
		var (
			existed bool
			err     error

			prompts         = prompt.New()
			conf            = config.New(nil)
			ker             *api.Ker
			domainList      *model.DomainListResponse
			records         []*model.Record
			recordsResponse *model.RecordsResponse
		)
		log.Println("Start to init config")

		if existed, err = conf.IfConfigIsExist(); err != nil {
			log.Fatalln(err)
			return
		} else if !existed {
			if err = conf.MkConfigDir(); err != nil {
				log.Fatalln(err)
				return
			}

			if err = conf.CreateConfig(); err != nil {
				log.Fatalln(err)
				return
			}
			log.Println("Create Config Success")
		}

		for conf.Email, err = prompts.SetEmail(); err != nil; {
			log.Println(err)
		}

		for conf.Token, err = prompts.SetToken(); err != nil; {
			log.Println(err)
		}

		ker = api.New(conf.Email, conf.Token)

		if domainList, err = ker.GetDomainList(); err != nil {
			log.Fatalln(err)
			return
		}

		for conf.Domain, err = prompts.SetDomain(domainList.Domains); err != nil; {
			log.Println(err)
		}

		if recordsResponse, err = ker.GetDomainRecords(conf.Domain); err != nil {
			log.Fatalln(err)
			return
		}

		for _, record := range recordsResponse.Records {
			if record.Type == constant.DomainTypeA || record.Type == constant.DomainTypeAAAA {
				records = append(records, record)
			}
		}

		for conf.Record, err = prompts.SetRecord(records); err != nil; {
			log.Println(err)
		}

		if err = conf.WriteConfig(); err != nil {
			log.Fatalln(err)
			return
		}

		log.Println("Save Config Success, pls use run command to test")
	},
}
View Source
var RunCmd = &cobra.Command{
	Use:   "run",
	Short: "run to test setting",
	Run: func(cmd *cobra.Command, args []string) {
		if err := run(); err != nil {
			log.Fatalln(err)
		}
	},
}
View Source
var StartCmd = &cobra.Command{
	Use:   "start",
	Short: "Start ddns service",
	Run: func(cmd *cobra.Command, args []string) {
		log.Println("Start ddns service, detecting every 1 minute")
		c := cron.New()
		if _, err := c.AddFunc("@every 1m", func() {
			run()
		}); err != nil {
			log.Fatalln(err)
			return
		}
		c.Start()

		select {}
	},
}
View Source
var VersionCmd = &cobra.Command{
	Use:   "version",
	Short: "Print hostker-ddns version",
	Run: func(cmd *cobra.Command, args []string) {
		fmt.Println("Hostker-DDNS version: ", version)
	},
}

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