mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-13 03:59:23 +02:00
Start work on porting the transfer kitten to Go
This commit is contained in:
62
kittens/transfer/main.go
Normal file
62
kittens/transfer/main.go
Normal 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)
|
||||
}
|
||||
@@ -102,3 +102,4 @@ elif __name__ == '__doc__':
|
||||
cd['usage'] = usage
|
||||
cd['options'] = option_text
|
||||
cd['help_text'] = help_text
|
||||
cd['short_desc'] = help_text
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//go:build exclude
|
||||
/*
|
||||
* rsync.c
|
||||
* Copyright (C) 2021 Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
Reference in New Issue
Block a user