cmd

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RootCommand = &cli.Command{
	Name:  "koeda",
	Usage: "Fuzzy find GitHub repositories",
	Action: func(c *cli.Context) error {
		cfg, err := config.Load()
		if err != nil {
			return err
		}
		ttl := cfg.TTL

		var repos []cache.Repo

		data, err := cache.Load()
		if err == nil {

			if cache.IsExpired(data.LastUpdate, ttl) {

				err = fmt.Errorf("cache expired")
			} else {
				repos = data.Repositories
			}
		}

		if err != nil {

			opts := github.FetchOptions{
				Affiliation: "owner,collaborator,organization_member",
				Visibility:  "all",
			}

			fmt.Fprintln(os.Stderr, "Updating repository cache...")

			_, err := DoUpdate(c.Context, opts)
			if err != nil {
				return fmt.Errorf("failed to update cache: %w", err)
			}

			data, loadErr := cache.Load()
			if loadErr != nil {
				return fmt.Errorf("failed to load cache after update: %w", loadErr)
			}
			repos = data.Repositories
		}

		if len(repos) == 0 {
			return fmt.Errorf("no repositories found")
		}

		selected, err := finder.Find(repos)
		if err != nil {
			if err.Error() == "abort" {

				return cli.Exit("cancelled", 130)
			}
			return err
		}

		fmt.Println(selected.FullName)
		return nil
	},
}
View Source
var UpdateCommand = &cli.Command{
	Name:  "update",
	Usage: "Update repository cache",
	Flags: []cli.Flag{
		&cli.StringFlag{
			Name:  "affiliation",
			Usage: "Comma-separated list of affiliations (owner, collaborator, organization_member)",
			Value: "owner,collaborator,organization_member",
		},
		&cli.StringFlag{
			Name:  "visibility",
			Usage: "Visibility of repositories (all, public, private)",
			Value: "all",
		},
		&cli.DurationFlag{
			Name:  "ttl",
			Usage: "Cache time-to-live",
		},
	},
	Action: func(c *cli.Context) error {
		if c.IsSet("ttl") {
			cfg, err := config.Load()
			if err != nil {
				return err
			}
			cfg.TTL = c.Duration("ttl")
			if err := config.Save(cfg); err != nil {
				return err
			}
		}

		start := time.Now()
		count, err := DoUpdate(c.Context, github.FetchOptions{
			Affiliation: c.String("affiliation"),
			Visibility:  c.String("visibility"),
		})
		if err != nil {
			return err
		}
		fmt.Printf("Updated %d repositories in %v.\n", count, time.Since(start).Round(time.Millisecond))
		return nil
	},
}

Functions

func DoUpdate

func DoUpdate(ctx context.Context, opts github.FetchOptions) (int, error)

DoUpdate fetches repos and saves them to cache. Returns the number of repos fetched.

Types

This section is empty.

Jump to

Keyboard shortcuts

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