-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add explore command for fetching and managing feeds from reposi…
…tories
- Loading branch information
Showing
11 changed files
with
958 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package cleed | ||
|
||
import ( | ||
"github.com/radulucut/cleed/internal" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func (r *Root) initExplore() { | ||
cmd := &cobra.Command{ | ||
Use: "explore", | ||
Short: "Explore feeds", | ||
Long: `Explore feeds from a repository | ||
Examples: | ||
# Explore feeds from the default repository | ||
cleed explore | ||
# Fetch the latest changes and explore feeds from the default repository | ||
cleed explore --update | ||
# Explore feeds from a repository | ||
cleed explore https://github.com/radulucut/cleed-explore.git | ||
# Limit the number of items to display from each list | ||
cleed explore --limit 5 | ||
# Search for items (title, description) | ||
cleed explore --search "news" | ||
# Import all feeds into my feeds | ||
cleed explore --import --limit 0 | ||
# Remove a repository | ||
cleed explore https://github.com/radulucut/cleed-explore.git --remove | ||
`, | ||
|
||
RunE: r.RunExplore, | ||
} | ||
|
||
flags := cmd.Flags() | ||
flags.Bool("import", false, "import feeds") | ||
flags.Uint("limit", 10, "limit the number of items to display from each list") | ||
flags.String("search", "", "search for items (title, description)") | ||
flags.BoolP("update", "u", false, "fetch the latest changes") | ||
flags.Bool("remove", false, "remove the repository") | ||
|
||
r.Cmd.AddCommand(cmd) | ||
} | ||
|
||
func (r *Root) RunExplore(cmd *cobra.Command, args []string) error { | ||
if cmd.Flag("remove").Changed { | ||
url := "" | ||
if len(args) > 0 { | ||
url = args[0] | ||
} | ||
return r.feed.ExploreRemove(url) | ||
} | ||
limit, err := cmd.Flags().GetUint("limit") | ||
if err != nil { | ||
return err | ||
} | ||
opts := &internal.ExploreOptions{ | ||
Limit: int(limit), | ||
Update: cmd.Flag("update").Changed, | ||
Query: cmd.Flag("search").Value.String(), | ||
} | ||
if len(args) > 0 { | ||
opts.Url = args[0] | ||
} | ||
if opts.Query != "" { | ||
if !cmd.Flag("limit").Changed { | ||
opts.Limit = 25 | ||
} | ||
return r.feed.ExploreSearch(opts) | ||
} | ||
if cmd.Flag("import").Changed { | ||
return r.feed.ExploreImport(opts) | ||
} | ||
return r.feed.Explore(opts) | ||
} |
Oops, something went wrong.