cmd

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2016 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AddCmd = &cobra.Command{
	Use:     "add <star|tag> <name>...",
	Short:   "Add stars or tags",
	Long:    "Add stars or tags. Adding a tag adds it to your local database. Adding a star stars the repository on the specified service.",
	Example: fmt.Sprintf("  %s add tag vim database\n  %s add star hoop33/limo --service github", config.ProgramName, config.ProgramName),
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) < 2 {
			getOutput().Fatal("You must specify star or tag and values")
		}

		if fn, ok := adders[args[0]]; ok {
			fn(args[1:])
		} else {
			getOutput().Fatal(fmt.Sprintf("'%s' not valid", args[0]))
		}
	},
}

AddCmd adds stars and tags

View Source
var DeleteCmd = &cobra.Command{
	Use:     "delete <tag>",
	Aliases: []string{"rm"},
	Short:   "Delete a tag",
	Long:    "Delete the tag named <tag>.",
	Example: fmt.Sprintf("  %s delete frameworks", config.ProgramName),
	Run: func(cmd *cobra.Command, args []string) {
		output := getOutput()

		if len(args) == 0 {
			output.Fatal("You must specify a tag")
		}

		db, err := getDatabase()
		fatalOnError(err)

		tag, err := model.FindTagByName(db, args[0])
		fatalOnError(err)

		if tag == nil {
			output.Fatal(fmt.Sprintf("Tag '%s' not found", args[0]))
		}

		fatalOnError(tag.Delete(db))

		output.Info(fmt.Sprintf("Deleted tag '%s'", tag.Name))
	},
}

DeleteCmd renames a tag

View Source
var ListCmd = &cobra.Command{
	Use:     "list <languages|stars|tags|trending>",
	Aliases: []string{"ls"},
	Short:   "List languages, stars, tags, or trending",
	Long:    "List languages, stars, tags, or trending that match your specified criteria.",
	Example: fmt.Sprintf("  %s list languages\n  %s list stars -t vim\n  %s list stars -t cli -l go", config.ProgramName, config.ProgramName, config.ProgramName),
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 {
			getOutput().Fatal("You must specify languages, stars, tags, or trending")
		}

		if fn, ok := listers[args[0]]; ok {
			fn(args)
		} else {
			getOutput().Fatal(fmt.Sprintf("'%s' not valid", args[0]))
		}
	},
}

ListCmd lists stars, tags, or trending

View Source
var LoginCmd = &cobra.Command{
	Use:     "login",
	Short:   "Log in to a service",
	Long:    "Log in to the service specified by [--service] (default: github).",
	Example: fmt.Sprintf("  %s login", config.ProgramName),
	Run: func(cmd *cobra.Command, args []string) {

		svc, err := getService()
		fatalOnError(err)

		token, err := svc.Login()
		fatalOnError(err)

		config, err := getConfiguration()
		fatalOnError(err)

		config.GetService(service.Name(svc)).Token = token
		fatalOnError(config.WriteConfig())
	},
}

LoginCmd lets you log in

View Source
var OpenCmd = &cobra.Command{
	Use:     "open <star>",
	Short:   "Open a star's URL",
	Long:    "Open a star's URL in your default browser.",
	Example: fmt.Sprintf("  %s open limo", config.ProgramName),
	Run: func(cmd *cobra.Command, args []string) {
		output := getOutput()

		if len(args) == 0 {
			output.Fatal("You must specify a star")
		}

		db, err := getDatabase()
		fatalOnError(err)

		stars, err := model.FuzzyFindStarsByName(db, args[0])
		fatalOnError(err)

		checkOneStar(args[0], stars)

		// The page to open
		var page string

		if homepage && stars[0].Homepage != nil && *stars[0].Homepage != "" {
			page = *stars[0].Homepage
		} else if stars[0].URL != nil && *stars[0].URL != "" {
			page = *stars[0].URL
		} else {
			output.Fatal("No URL for star")
		}

		output.Info(fmt.Sprintf("Opening %s...", page))
		fatalOnError(open.Start(page))
	},
}

OpenCmd opens a star's URL in your browser

View Source
var RenameCmd = &cobra.Command{
	Use:     "rename <tag> <name>",
	Aliases: []string{"mv"},
	Short:   "Rename a tag",
	Long:    "Rename the tag with name <tag> to <name>.",
	Example: fmt.Sprintf("  %s rename www web", config.ProgramName),
	Run: func(cmd *cobra.Command, args []string) {
		output := getOutput()

		if len(args) < 2 {
			output.Fatal("You must specify a tag and a new name")
		}

		db, err := getDatabase()
		fatalOnError(err)

		tag, err := model.FindTagByName(db, args[0])
		fatalOnError(err)

		if tag == nil {
			output.Fatal(fmt.Sprintf("Tag '%s' not found", args[0]))
		}

		fatalOnError(tag.Rename(db, args[1]))

		output.Info(fmt.Sprintf("Renamed tag '%s' to '%s'", args[0], tag.Name))
	},
}

RenameCmd renames a tag

View Source
var RootCmd = &cobra.Command{
	Use:   "limo",
	Short: "A CLI for managing starred repositories",
	Long: `limo allows you to manage your starred repositories on GitHub, GitLab, and Bitbucket.
You can tag, display, and search your starred repositories.`,
}

RootCmd is the root command for limo

View Source
var SearchCmd = &cobra.Command{
	Use:     "search <search string>",
	Aliases: []string{"find", "query", "q"},
	Short:   "Search stars",
	Long:    "Perform a full-text search on your stars",
	Example: fmt.Sprintf("  %s search robust", config.ProgramName),
	Run: func(cmd *cobra.Command, args []string) {
		output := getOutput()

		if len(args) == 0 {
			output.Fatal("You must specify a search string")
		}

		index, err := getIndex()
		fatalOnError(err)

		query := bleve.NewMatchQuery(strings.Join(args, " "))
		request := bleve.NewSearchRequest(query)
		results, err := index.Search(request)
		fatalOnError(err)

		db, err := getDatabase()
		fatalOnError(err)

		for _, hit := range results.Hits {
			ID, err := strconv.Atoi(hit.ID)
			if err != nil {
				output.Error(err.Error())
			} else {
				star, err := model.FindStarByID(db, uint(ID))
				if err != nil {
					output.Error(err.Error())
				} else {
					output.Inline(fmt.Sprintf("(%f) ", hit.Score))
					output.StarLine(star)
				}
			}
		}
	},
}

SearchCmd does a full-text search

View Source
var ShowCmd = &cobra.Command{
	Use:     "show <star>",
	Short:   "Show a star's details",
	Long:    "Show details about the star identified by <star>.",
	Example: fmt.Sprintf("  %s show limo", config.ProgramName),
	Run: func(cmd *cobra.Command, args []string) {
		output := getOutput()

		if len(args) == 0 {
			output.Fatal("You must specify a star")
		}

		db, err := getDatabase()
		fatalOnError(err)

		stars, err := model.FuzzyFindStarsByName(db, args[0])
		fatalOnError(err)

		for _, star := range stars {
			err = star.LoadTags(db)
			if err != nil {
				output.Error(err.Error())
			} else {
				output.Star(&star)
				output.Info("")
			}
		}
	},
}

ShowCmd shows the version

View Source
var TagCmd = &cobra.Command{
	Use:     "tag <star> <tag>...",
	Short:   "Tag a star",
	Long:    "Tag the star identified by <star> with the tags specified by <tag>, creating tags as necessary.",
	Example: fmt.Sprintf("  %s tag limo git cli", config.ProgramName),
	Run: func(cmd *cobra.Command, args []string) {
		output := getOutput()

		if len(args) < 2 {
			output.Fatal("You must specify a star and at least one tag")
		}

		db, err := getDatabase()
		fatalOnError(err)

		stars, err := model.FuzzyFindStarsByName(db, args[0])
		fatalOnError(err)

		checkOneStar(args[0], stars)

		output.StarLine(&stars[0])
		for _, tagName := range args[1:] {
			tag, _, err := model.FindOrCreateTagByName(db, tagName)
			if err != nil {
				output.Error(err.Error())
			} else {
				err = stars[0].AddTag(db, tag)
				if err != nil {
					output.Error(err.Error())
				} else {
					output.Info(fmt.Sprintf("Added tag '%s'", tag.Name))
				}
			}
		}
	},
}

TagCmd tags a star

View Source
var UntagCmd = &cobra.Command{
	Use:     "untag <star> [tag]...",
	Short:   "Untag a star",
	Long:    "Untag the star identified by <star> with the tags specified by [tag], or all if [tag] not specified.",
	Example: fmt.Sprintf("  %s untag limo gui", config.ProgramName),
	Run: func(cmd *cobra.Command, args []string) {
		output := getOutput()

		if len(args) == 0 {
			output.Fatal("You must specify a star (and optionally a tag)")
		}

		db, err := getDatabase()
		fatalOnError(err)

		stars, err := model.FuzzyFindStarsByName(db, args[0])
		fatalOnError(err)

		checkOneStar(args[0], stars)

		output.StarLine(&stars[0])

		if len(args) == 1 {

			fatalOnError(stars[0].RemoveAllTags(db))
			output.Info(fmt.Sprintf("Removed all tags"))
		} else {
			fatalOnError(stars[0].LoadTags(db))

			for _, tagName := range args[1:] {
				tag, err := model.FindTagByName(db, tagName)
				if err != nil {
					output.Error(err.Error())
				} else if tag == nil {
					output.Error(fmt.Sprintf("Tag '%s' does not exist", tagName))
				} else if !stars[0].HasTag(tag) {
					output.Error(fmt.Sprintf("'%s' isn't tagged with '%s'", *stars[0].FullName, tagName))
				} else {
					err = stars[0].RemoveTag(db, tag)
					if err != nil {
						output.Error(err.Error())
					} else {
						output.Info(fmt.Sprintf("Removed tag '%s'", tag.Name))
					}
				}
			}
		}
	},
}

UntagCmd tags a star

View Source
var UpdateCmd = &cobra.Command{
	Use:     "update",
	Short:   "Update stars from a service",
	Long:    "Update your local database with your stars from the service specified by [--service] (default: github).",
	Example: fmt.Sprintf("  %s update", config.ProgramName),
	Run: func(cmd *cobra.Command, args []string) {

		cfg, err := getConfiguration()
		fatalOnError(err)

		db, err := getDatabase()
		fatalOnError(err)

		index, err := getIndex()
		fatalOnError(err)

		svc, err := getService()
		fatalOnError(err)

		serviceName := service.Name(svc)
		dbSvc, _, err := model.FindOrCreateServiceByName(db, serviceName)
		fatalOnError(err)

		starChan := make(chan *model.StarResult, 20)

		go svc.GetStars(starChan, cfg.GetService(serviceName).Token, "")

		output := getOutput()

		totalCreated, totalUpdated, totalErrors := 0, 0, 0

		for starResult := range starChan {
			if starResult.Error != nil {
				totalErrors++
				output.Error(starResult.Error.Error())
			} else {
				created, err := model.CreateOrUpdateStar(db, starResult.Star, dbSvc)
				if err != nil {
					totalErrors++
					output.Error(fmt.Sprintf("Error %s: %s", *starResult.Star.FullName, err.Error()))
				} else {
					if created {
						totalCreated++
					} else {
						totalUpdated++
					}
					err = starResult.Star.Index(index, db)
					if err != nil {
						totalErrors++
						output.Error(fmt.Sprintf("Error %s: %s", *starResult.Star.FullName, err.Error()))
					}
					output.Tick()
				}
			}
		}
		output.Info(fmt.Sprintf("\nCreated: %d; Updated: %d; Errors: %d", totalCreated, totalUpdated, totalErrors))
	},
}

UpdateCmd lets you log in

View Source
var VersionCmd = &cobra.Command{
	Use:     "version",
	Short:   "Display version information",
	Long:    fmt.Sprintf("Display version information for %s.", config.ProgramName),
	Example: fmt.Sprintf("  %s version", config.ProgramName),
	Run: func(cmd *cobra.Command, args []string) {
		getOutput().Info(config.Version)
	},
}

VersionCmd shows the version

Functions

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately.

Types

This section is empty.

Jump to

Keyboard shortcuts

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