mirror of
https://github.com/rclone/rclone.git
synced 2024-11-26 02:14:42 +01:00
rc: added command core/quit
This commit is contained in:
parent
9cb549a227
commit
0c265713fd
@ -6,11 +6,14 @@ import (
|
||||
"context"
|
||||
"os"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/rclone/rclone/fs"
|
||||
"github.com/rclone/rclone/fs/config/obscure"
|
||||
"github.com/rclone/rclone/fs/version"
|
||||
"github.com/rclone/rclone/lib/atexit"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -224,3 +227,36 @@ func rcObscure(ctx context.Context, in Params) (out Params, err error) {
|
||||
}
|
||||
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"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/rclone/rclone/fs"
|
||||
"github.com/rclone/rclone/fs/config/obscure"
|
||||
"github.com/rclone/rclone/fs/version"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestInternalNoop(t *testing.T) {
|
||||
@ -107,3 +108,14 @@ func TestCoreObscure(t *testing.T) {
|
||||
require.NotNil(t, out)
|
||||
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…
Reference in New Issue
Block a user