Documentation
¶
Overview ¶
Package cli provides the command line interface for the bucket application.
Index ¶
- Constants
- Variables
- func InitializeContexts(loadDatabase bool) func(*cli.Context) error
- func ReadKeycode(in io.Reader) (int, error)
- func ReadSequence(in io.Reader) (int, error)
- func ShutdownContexts(c *cli.Context) error
- func TableSelect(options []string, out io.Writer) (int, error)
- func TableSelectPlain(options []string, out io.Writer) (int, error)
- type Table
Constants ¶
View Source
const ( UP = iota + 1 DOWN RIGHT LEFT )
View Source
const CTRLC = '\x03'
View Source
const ENTER = -13
View Source
const SEQUENCE = '\x1b'
Variables ¶
View Source
var ADD = &cli.Command{ Name: "add", Aliases: []string{"a"}, Usage: "adds a plugin to the server", Before: InitializeContexts(true), After: ShutdownContexts, Args: true, ArgsUsage: " name", Action: func(c *cli.Context) error { if c.Args().Len() == 0 { return cli.Exit("missing plugin name", 1) } return Workspace.RunWithContext("add", func(oc *bucket.OpenContext, log *log.Logger) error { const REPO = "modrinth" if oc.Platform == nil { return cli.Exit("no platform set", 1) } res, _, err := oc.Repositories[REPO].Search(c.Args().Get(0), 5) if err != nil { return err } if len(res) > 5 { res = res[:5] } else if len(res) == 0 { return cli.Exit("no plugins found", 1) } options := make([]string, len(res)) for i, v := range res { options[i] = fmt.Sprintf("[%s] %s", v.GetRepository().Provider(), v.GetName()) } log.Println("Select a plugin to install") n, err := TableSelect(options, os.Stderr) if err != nil { return err } log.Printf("Selected %s\n\n", options[n]) pl := res[n] ver, err := pl.GetLatestVersion() if err != nil { return err } log.Printf("Installing %s [%s]\n", pl.GetName(), ver.GetIdentifier()) files, err := ver.GetFiles() if err != nil { return err } oc.Fs.MkdirAll(oc.Platform.PluginsFolder(), 0755) folder := afero.NewBasePathFs(oc.Fs, oc.Platform.PluginsFolder()) for _, f := range files { if !f.Optional() { log.Printf("Downloading %s\n", f.Name()) data, err := f.Download() if err != nil { return err } defer data.Close() fd, err := folder.OpenFile(f.Name(), os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644) if err != nil { return err } defer fd.Close() if _, err := io.Copy(fd, data); err != nil { return err } if err := fd.Close(); err != nil { return err } if err := f.Verify(); err != nil { return err } else { log.Printf("File %s verified\n", f.Name()) } pl, err := oc.Platform.LoadPlugin(f.Name()) if err != nil { return err } err = oc.SavePlugin(bucket.CachedMatch(pl, ver, oc.Repositories[REPO], 1.0)) if err != nil { return err } log.Printf("Plugin %s saved\n", pl.GetName()) } else { log.Printf("Skipping optional file %s\n", f.Name()) } } return nil }) }, }
View Source
var CLEAN = &cli.Command{ Name: "clean", Aliases: []string{"c"}, Usage: "discards the plugin cache", Before: InitializeContexts(false), After: ShutdownContexts, Action: func(c *cli.Context) error { return Workspace.RunWithContext("clean", func(oc *bucket.OpenContext, log *log.Logger) error { size, err := oc.DBSize() if err != nil { return err } log.Printf("deleting database file (%d KB)\n", size/1024) if err := oc.CleanCache(); err != nil { return err } if c.Args().Len() > 0 { if c.Args().Get(0) == "all" { var size int64 if size, err = oc.PluginsSize(); err != nil { return err } log.Printf("deleting plugin cache (%.2f MB)\n", float64(size)/1024/1024) if err = oc.Fs.RemoveAll(oc.Platform.PluginsFolder()); err != nil { return err } } } return nil }) }, }
View Source
var DEBUG = &cli.Command{ Name: "debug", Usage: "runs debug routine", Before: InitializeContexts(true), After: ShutdownContexts, Action: func(c *cli.Context) error { return Workspace.RunWithContext("debug", func(oc *bucket.OpenContext, log *log.Logger) error { return bucket.DebugRoutine(oc, log) }) }, }
View Source
var GlobalError error
View Source
var Time time.Time
View Source
var Workspace *bucket.Workspace
Functions ¶
func ShutdownContexts ¶
Types ¶
Click to show internal directories.
Click to hide internal directories.