forked from TrueCloudLab/rclone
rc: added command core/quit
This commit is contained in:
parent
9cb549a227
commit
0c265713fd
2 changed files with 50 additions and 2 deletions
|
@ -6,11 +6,14 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/rclone/rclone/fs"
|
"github.com/rclone/rclone/fs"
|
||||||
"github.com/rclone/rclone/fs/config/obscure"
|
"github.com/rclone/rclone/fs/config/obscure"
|
||||||
"github.com/rclone/rclone/fs/version"
|
"github.com/rclone/rclone/fs/version"
|
||||||
|
"github.com/rclone/rclone/lib/atexit"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -224,3 +227,36 @@ func rcObscure(ctx context.Context, in Params) (out Params, err error) {
|
||||||
}
|
}
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
Add(Call{
|
||||||
|
Path: "core/quit",
|
||||||
|
Fn: rcQuit,
|
||||||
|
Title: "Terminates the app.",
|
||||||
|
Help: `
|
||||||
|
(optional) Pass an exit code to be used for terminating the app:
|
||||||
|
- exitCode - int
|
||||||
|
`,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Terminates app
|
||||||
|
func rcQuit(ctx context.Context, in Params) (out Params, err error) {
|
||||||
|
code, err := in.GetInt64("exitCode")
|
||||||
|
|
||||||
|
if IsErrParamInvalid(err) {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if IsErrParamNotFound(err) {
|
||||||
|
code = 0
|
||||||
|
}
|
||||||
|
exitCode := int(code)
|
||||||
|
|
||||||
|
go func(exitCode int) {
|
||||||
|
time.Sleep(time.Millisecond * 1500)
|
||||||
|
atexit.Run()
|
||||||
|
os.Exit(exitCode)
|
||||||
|
}(exitCode)
|
||||||
|
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
|
@ -5,11 +5,12 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/rclone/rclone/fs"
|
"github.com/rclone/rclone/fs"
|
||||||
"github.com/rclone/rclone/fs/config/obscure"
|
"github.com/rclone/rclone/fs/config/obscure"
|
||||||
"github.com/rclone/rclone/fs/version"
|
"github.com/rclone/rclone/fs/version"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestInternalNoop(t *testing.T) {
|
func TestInternalNoop(t *testing.T) {
|
||||||
|
@ -107,3 +108,14 @@ func TestCoreObscure(t *testing.T) {
|
||||||
require.NotNil(t, out)
|
require.NotNil(t, out)
|
||||||
assert.Equal(t, in["clear"], obscure.MustReveal(out["obscured"].(string)))
|
assert.Equal(t, in["clear"], obscure.MustReveal(out["obscured"].(string)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCoreQuit(t *testing.T) {
|
||||||
|
//The call should return an error if param exitCode is not parsed to int
|
||||||
|
call := Calls.Get("core/quit")
|
||||||
|
assert.NotNil(t, call)
|
||||||
|
in := Params{
|
||||||
|
"exitCode": "potato",
|
||||||
|
}
|
||||||
|
_, err := call.Fn(context.Background(), in)
|
||||||
|
require.Error(t, err)
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue