Skip to content

Commit

Permalink
Added gdown completer (#2698)
Browse files Browse the repository at this point in the history
* Added gdown completer

* Update completers/gdown_completer/cmd/actions/speed.go

Co-authored-by: Ralf Steube <[email protected]>

* Update speed.go

* Update root.go

* Update root.go

---------

Co-authored-by: Ralf Steube <[email protected]>
  • Loading branch information
Saurabh825 and rsteube authored Feb 9, 2025
1 parent 9f705b3 commit d205777
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
16 changes: 16 additions & 0 deletions completers/gdown_completer/cmd/actions/speed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package actions

import (
"github.com/carapace-sh/carapace"
"regexp"
)

func ActionSpeed() carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
r := regexp.MustCompile(`^(?P<digits>\d+).*$`)
if matches := r.FindStringSubmatch(c.Value); matches != nil {
return carapace.ActionValues("KB", "MB", "GB").Prefix(matches[1])
}
return carapace.ActionValues()
})
}
47 changes: 47 additions & 0 deletions completers/gdown_completer/cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/completers/gdown_completer/cmd/actions"
"github.com/spf13/cobra"
)

var rootCmd = &cobra.Command{
Use: "gdown",
Short: "Google Drive Public File Downloader when Curl/Wget Fails",
Long: "https://github.com/wkentaro/gdown",
Run: func(cmd *cobra.Command, args []string) {},
}

func Execute() error {
return rootCmd.Execute()
}

func init() {
carapace.Gen(rootCmd).Standalone()

rootCmd.Flags().BoolP("continue", "c", false, "resume getting partially-downloaded files")
rootCmd.Flags().Bool("folder", false, "download entire folder instead of a single file")
rootCmd.Flags().String("format", "", "Format of Google Docs, Spreadsheets, and Slides")
rootCmd.Flags().Bool("fuzzy", false, "extract Google Drive's file ID")
rootCmd.Flags().BoolP("help", "h", false, "show this help message and exit")
rootCmd.Flags().Bool("no-check-certificate", false, "don't check the server's TLS certificate")
rootCmd.Flags().Bool("no-cookies", false, "don't use cookies in ~/.cache/gdown/cookies.txt")
rootCmd.Flags().StringP("output", "O", "", "output file name/path")
rootCmd.Flags().String("proxy", "", "download using the specified proxy")
rootCmd.Flags().BoolP("quiet", "q", false, "suppress logging except errors")
rootCmd.Flags().Bool("remaining-ok", false, "asserts that is ok to download max 50 files per folder")
rootCmd.Flags().String("speed", "", "download speed limit in second")
rootCmd.Flags().String("user-agent", "", "User-Agent to use for downloading file")
rootCmd.Flags().BoolP("version", "V", false, "display version")

carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{
"format": carapace.ActionValuesDescribed(
"docx", "Google Docs",
"xlsx", "Spreadsheet",
"pptx", "Slides",
),
"output": carapace.ActionFiles(),
"speed": actions.ActionSpeed(),
})
}
7 changes: 7 additions & 0 deletions completers/gdown_completer/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "github.com/carapace-sh/carapace-bin/completers/gdown_completer/cmd"

func main() {
cmd.Execute()
}

0 comments on commit d205777

Please sign in to comment.