Use a single wrapper binary for all command line tools

This is because Go has a multi megabyte overhead for its binaries
This commit is contained in:
Kovid Goyal
2022-08-15 08:16:00 +05:30
parent abaafc2d68
commit aaf0dea8dc
5 changed files with 60 additions and 36 deletions

View File

@@ -1,10 +1,7 @@
package main
package at
import (
"fmt"
"os"
"github.com/fatih/color"
"github.com/spf13/cobra"
"kitty/tools/cli"
@@ -12,18 +9,13 @@ import (
)
var encrypt_cmd = crypto.Encrypt_cmd
var exe_name = "kitty-at"
func main() {
func EntryPoint(tool_root *cobra.Command) *cobra.Command {
var root = cli.CreateCommand(&cobra.Command{
Use: "[global options] command [command options] [command args]",
Use: "@ [global options] command [command options] [command args]",
Short: "Control kitty remotely",
Long: "Control kitty by sending it commands. Set the allow_remote_control option in kitty.conf or use a password, for this to work.",
Run: func(cmd *cobra.Command, args []string) {
cmd.Usage()
fmt.Fprintln(os.Stderr, color.RedString("\nNo command specified for "+exe_name))
},
}, exe_name)
})
root.Annotations["options_title"] = "Global options"
root.PersistentFlags().String("password", "",
@@ -32,9 +24,5 @@ func main() {
" accepted before or is pre-configured in :file:`kitty.conf`.")
cli.PersistentChoices(root, "use-password", "If no password is available, kitty will usually just send the remote control command without a password. This option can be used to force it to always or never use the supplied password.", "if-available", "always", "never")
cli.Init(root)
if err := root.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
return root
}

25
tools/cmd/main.go Normal file
View File

@@ -0,0 +1,25 @@
package main
import (
"fmt"
"os"
"github.com/spf13/cobra"
"kitty/tools/cli"
"kitty/tools/cmd/at"
)
func main() {
var root = cli.CreateCommand(&cobra.Command{
Use: "kitty-tool command [command options] [command args]",
Short: "Fast, statically compiled implementations for various kitty command-line tools",
})
root.AddCommand(at.EntryPoint(root))
cli.Init(root)
if err := root.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}