Start work on porting the transfer kitten to Go

This commit is contained in:
Kovid Goyal
2023-04-27 15:40:26 +05:30
parent 02c9205061
commit 7cec9016d3
5 changed files with 68 additions and 1 deletions

62
kittens/transfer/main.go Normal file
View File

@@ -0,0 +1,62 @@
// License: GPLv3 Copyright: 2023, Kovid Goyal, <kovid at kovidgoyal.net>
package transfer
import (
"fmt"
"io"
"os"
"strconv"
"strings"
"kitty/tools/cli"
"kitty/tools/utils"
)
var _ = fmt.Print
func read_bypass(loc string) (string, error) {
if loc == "" {
return "", nil
}
fdnum, err := strconv.Atoi(loc)
if err == nil && fdnum >= 0 && fdnum < 256 && loc[0] >= '0' && loc[0] <= '9' {
file := os.NewFile(uintptr(fdnum), loc)
defer file.Close()
raw, err := io.ReadAll(file)
return utils.UnsafeBytesToString(raw), err
}
if loc == "-" {
raw, err := io.ReadAll(os.Stdin)
defer os.Stdin.Close()
return utils.UnsafeBytesToString(raw), err
}
switch loc[0] {
case '.', '~', '/':
if loc[0] == '~' {
loc = utils.Expanduser(loc)
}
raw, err := os.ReadFile(loc)
return utils.UnsafeBytesToString(raw), err
default:
return loc, nil
}
}
func main(cmd *cli.Command, opts *Options, args []string) (rc int, err error) {
if err != nil {
rc = 1
}
if opts.PermissionsBypass != "" {
val, err := read_bypass(opts.PermissionsBypass)
if err != nil {
return 1, err
}
opts.PermissionsBypass = strings.TrimSpace(val)
}
return
}
func EntryPoint(parent *cli.Command) {
create_cmd(parent, main)
}

View File

@@ -102,3 +102,4 @@ elif __name__ == '__doc__':
cd['usage'] = usage cd['usage'] = usage
cd['options'] = option_text cd['options'] = option_text
cd['help_text'] = help_text cd['help_text'] = help_text
cd['short_desc'] = help_text

View File

@@ -1,3 +1,4 @@
//go:build exclude
/* /*
* rsync.c * rsync.c
* Copyright (C) 2021 Kovid Goyal <kovid at kovidgoyal.net> * Copyright (C) 2021 Kovid Goyal <kovid at kovidgoyal.net>

View File

@@ -24,7 +24,7 @@ exec_kitty() {
is_wrapped_kitten() { is_wrapped_kitten() {
wrapped_kittens="clipboard icat hyperlinked_grep ask hints unicode_input ssh themes diff show_key" wrapped_kittens="clipboard icat hyperlinked_grep ask hints unicode_input ssh themes diff show_key transfer"
[ -n "$1" ] && { [ -n "$1" ] && {
case " $wrapped_kittens " in case " $wrapped_kittens " in
*" $1 "*) printf "%s" "$1" ;; *" $1 "*) printf "%s" "$1" ;;

View File

@@ -14,6 +14,7 @@ import (
"kitty/kittens/show_key" "kitty/kittens/show_key"
"kitty/kittens/ssh" "kitty/kittens/ssh"
"kitty/kittens/themes" "kitty/kittens/themes"
"kitty/kittens/transfer"
"kitty/kittens/unicode_input" "kitty/kittens/unicode_input"
"kitty/tools/cli" "kitty/tools/cli"
"kitty/tools/cmd/at" "kitty/tools/cmd/at"
@@ -43,6 +44,8 @@ func KittyToolEntryPoints(root *cli.Command) {
icat.EntryPoint(root) icat.EntryPoint(root)
// ssh // ssh
ssh.EntryPoint(root) ssh.EntryPoint(root)
// transfer
transfer.EntryPoint(root)
// unicode_input // unicode_input
unicode_input.EntryPoint(root) unicode_input.EntryPoint(root)
// show_key // show_key