platform

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// AuthCmd support auth with cookie or other raw auth data
	AuthCmd = &cobra.Command{
		Use:   "auth",
		Short: "Authenticate",
		RunE: func(cmd *cobra.Command, args []string) error {
			pf, err := platform.GetByName(PfName)
			if err != nil {
				return errors.Trace(err)
			}

			loggedIn, err := pf.Auth(rawAuth)
			if err != nil {
				return errors.Trace(err)
			}

			config.Cfg.SetAuth(PfName, rawAuth)
			err = config.Save()
			if err != nil {
				return errors.Trace(err)
			}

			fmt.Printf("Logged in as %s\n", loggedIn)
			return nil
		},
	}
)
View Source
var (
	// PfName Specify platform name
	PfName string
)
View Source
var (

	// PublishCmd Publish article from a local file
	PublishCmd = &cobra.Command{
		Use:   "pub",
		Short: "Publish article",
		RunE: func(cmd *cobra.Command, args []string) error {
			pf, err := platform.GetByName(PfName)
			if err != nil {
				return errors.Trace(err)
			}
			t := time.Now()
			if _, err := pf.Auth(config.Cfg.Auth[pf.Name()]); err != nil {
				return errors.Trace(err)
			}
			fmt.Printf("auth took %v\n", time.Since(t))

			f, err := os.Open(file)
			if err != nil {
				return errors.Trace(err)
			}
			if err = pf.NewArticle(f); err != nil {
				return errors.Trace(err)
			}

			t = time.Now()
			url, err := pf.Publish()
			if err != nil {
				return errors.Trace(err)
			}
			fmt.Printf("publish took %v\n", time.Since(t))
			fmt.Printf("article url: %s\n", url)
			return nil
		},
	}
)

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