internal

package
v0.0.0-...-65ae855 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TrimCommand = cli.Command{
	Name:      "trim",
	Usage:     "remove leading and trailing spaces from page title",
	ArgsUsage: "<page_id>",
	Flags: []cli.Flag{
		&cli.BoolFlag{
			Name:    "recursive",
			Aliases: []string{"r"},
			Usage:   "process child pages recursively",
		},
	},
	Action: func(c *cli.Context) error {
		if c.NArg() < 1 {
			return cli.Exit("please provide page id", 1)
		}

		n := notion.NewClient(c.String("token"))

		page, err := n.FindPageByID(context.Background(), c.Args().First())
		if err != nil {
			return cli.Exit(err, 2)
		}

		if c.Bool("recursive") {
			fmt.Fprintf(c.App.Writer, "trimming page titles recursively, any errors will not lead to non-zero exit code\n")

			for _, err := range trimPageTitlesRecursively(c, n, []notion.Page{page}) {
				if err != nil {
					fmt.Fprintf(c.App.ErrWriter, "error trimming page %s: %s\n", page.ID, err)
				}
			}
		} else {
			if err := trimPageTitle(c, n, page); err != nil {
				return cli.Exit(err, 2)
			}
		}

		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