mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Move and refactor files and some more changes :3
This commit is contained in:
parent
781e520591
commit
303689ecbb
29 changed files with 1305 additions and 1160 deletions
85
cli/root.go
Normal file
85
cli/root.go
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/ByteDream/crunchy-cli/cli/commands"
|
||||
"github.com/ByteDream/crunchy-cli/cli/commands/archive"
|
||||
"github.com/ByteDream/crunchy-cli/cli/commands/download"
|
||||
"github.com/ByteDream/crunchy-cli/cli/commands/info"
|
||||
"github.com/ByteDream/crunchy-cli/cli/commands/login"
|
||||
"github.com/ByteDream/crunchy-cli/cli/commands/update"
|
||||
"github.com/ByteDream/crunchy-cli/utils"
|
||||
"github.com/spf13/cobra"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
quietFlag bool
|
||||
verboseFlag bool
|
||||
|
||||
proxyFlag string
|
||||
|
||||
useragentFlag string
|
||||
)
|
||||
|
||||
var RootCmd = &cobra.Command{
|
||||
Use: "crunchy-cli",
|
||||
Version: utils.Version,
|
||||
Short: "Download crunchyroll videos with ease. See the wiki for details about the cli and library: https://github.com/ByteDream/crunchy-cli/wiki",
|
||||
|
||||
SilenceErrors: true,
|
||||
SilenceUsage: true,
|
||||
|
||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||
if verboseFlag {
|
||||
utils.Log = commands.NewLogger(true, true, true)
|
||||
} else if quietFlag {
|
||||
utils.Log = commands.NewLogger(false, false, false)
|
||||
}
|
||||
|
||||
utils.Log.Debug("Executing `%s` command with %d arg(s)", cmd.Name(), len(args))
|
||||
|
||||
utils.Client, err = utils.CreateOrDefaultClient(proxyFlag, useragentFlag)
|
||||
return
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
RootCmd.PersistentFlags().BoolVarP(&quietFlag, "quiet", "q", false, "Disable all output")
|
||||
RootCmd.PersistentFlags().BoolVarP(&verboseFlag, "verbose", "v", false, "Adds debug messages to the normal output")
|
||||
|
||||
RootCmd.PersistentFlags().StringVarP(&proxyFlag, "proxy", "p", "", "Proxy to use")
|
||||
|
||||
RootCmd.PersistentFlags().StringVar(&useragentFlag, "useragent", fmt.Sprintf("crunchy-cli/%s", utils.Version), "Useragent to do all request with")
|
||||
|
||||
RootCmd.AddCommand(archive.Cmd)
|
||||
RootCmd.AddCommand(download.Cmd)
|
||||
RootCmd.AddCommand(info.Cmd)
|
||||
RootCmd.AddCommand(login.Cmd)
|
||||
RootCmd.AddCommand(update.Cmd)
|
||||
|
||||
utils.Log = commands.NewLogger(false, true, true)
|
||||
}
|
||||
|
||||
func Execute() {
|
||||
RootCmd.CompletionOptions.HiddenDefaultCmd = true
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
if utils.Log.IsDev() {
|
||||
utils.Log.Err("%v: %s", r, debug.Stack())
|
||||
} else {
|
||||
utils.Log.Err("Unexpected error: %v", r)
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
||||
}()
|
||||
if err := RootCmd.Execute(); err != nil {
|
||||
if !strings.HasSuffix(err.Error(), context.Canceled.Error()) {
|
||||
utils.Log.Err("An error occurred: %v", err)
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue