Refactor function command (#1372)
This commit is contained in:
@@ -16,6 +16,10 @@ limitations under the License.
|
||||
|
||||
package cli
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
Input interface {
|
||||
//Parse(input interface{}) error
|
||||
@@ -30,19 +34,19 @@ type (
|
||||
// String returns string value of given flag.
|
||||
String(key string) string
|
||||
|
||||
// StringSlice returns string slice of given flag..
|
||||
// StringSlice returns string slice of given flag.
|
||||
StringSlice(key string) []string
|
||||
|
||||
// Int returns int value of given flag.nd false.
|
||||
// Int returns int value of given flag.
|
||||
Int(key string) int
|
||||
|
||||
// IntSlice returns int slice of given flag.lse.
|
||||
// IntSlice returns int slice of given flag.
|
||||
IntSlice(key string) []int
|
||||
|
||||
// Int64 returns int64 value of given flag. false.
|
||||
// Int64 returns int64 value of given flag.
|
||||
Int64(key string) int64
|
||||
|
||||
// Int64Slice returns int64 slice of given flag.e.
|
||||
// Int64Slice returns int64 slice of given flag.
|
||||
Int64Slice(key string) []int64
|
||||
|
||||
// GlobalBool returns true if given global flag has been set;
|
||||
@@ -66,5 +70,8 @@ type (
|
||||
|
||||
// GlobalInt64Slice returns global int64 slice of given flag.
|
||||
GlobalInt64Slice(key string) []int64
|
||||
|
||||
// Duration returns time duration of given flag.
|
||||
Duration(key string) time.Duration
|
||||
}
|
||||
)
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
Copyright 2019 The Fission Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package dummy
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
fCli "github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
)
|
||||
|
||||
var _ fCli.Input = &Cli{}
|
||||
|
||||
type Cli struct {
|
||||
c map[string]interface{}
|
||||
}
|
||||
|
||||
// TestFlagSet returns a flag set for unit test purpose.
|
||||
func TestFlagSet() Cli {
|
||||
return Cli{c: make(map[string]interface{})}
|
||||
}
|
||||
|
||||
// Set allows to set any kinds of value with given key.
|
||||
// The type of set value should be matched with the returned
|
||||
// type of GetXXX function.
|
||||
func (u Cli) Set(Key string, value interface{}) {
|
||||
u.c[Key] = value
|
||||
}
|
||||
|
||||
func (u Cli) IsSet(key string) bool {
|
||||
_, ok := u.c[key]
|
||||
return ok
|
||||
}
|
||||
|
||||
func (u Cli) Bool(key string) bool {
|
||||
val, ok := u.c[key]
|
||||
if !ok || val == nil {
|
||||
return false
|
||||
}
|
||||
return val.(bool)
|
||||
}
|
||||
|
||||
func (u Cli) String(key string) string {
|
||||
val, ok := u.c[key]
|
||||
if !ok || val == nil {
|
||||
return ""
|
||||
}
|
||||
return val.(string)
|
||||
}
|
||||
|
||||
func (u Cli) StringSlice(key string) []string {
|
||||
val, ok := u.c[key]
|
||||
if !ok || val == nil {
|
||||
return nil
|
||||
}
|
||||
return val.([]string)
|
||||
}
|
||||
|
||||
func (u Cli) Int(key string) int {
|
||||
val, ok := u.c[key]
|
||||
if !ok || val == nil {
|
||||
return 0
|
||||
}
|
||||
return val.(int)
|
||||
}
|
||||
|
||||
func (u Cli) IntSlice(key string) []int {
|
||||
val, ok := u.c[key]
|
||||
if !ok || val == nil {
|
||||
return nil
|
||||
}
|
||||
return val.([]int)
|
||||
}
|
||||
|
||||
func (u Cli) Int64(key string) int64 {
|
||||
val, ok := u.c[key]
|
||||
if !ok || val == nil {
|
||||
return 0
|
||||
}
|
||||
return val.(int64)
|
||||
}
|
||||
|
||||
func (u Cli) Int64Slice(key string) []int64 {
|
||||
val, ok := u.c[key]
|
||||
if !ok || val == nil {
|
||||
return nil
|
||||
}
|
||||
return val.([]int64)
|
||||
}
|
||||
|
||||
func (u Cli) GlobalBool(key string) bool {
|
||||
val, ok := u.c[key]
|
||||
if !ok || val == nil {
|
||||
return false
|
||||
}
|
||||
return val.(bool)
|
||||
}
|
||||
|
||||
func (u Cli) GlobalString(key string) string {
|
||||
val, ok := u.c[key]
|
||||
if !ok || val == nil {
|
||||
return ""
|
||||
}
|
||||
return val.(string)
|
||||
}
|
||||
|
||||
func (u Cli) GlobalStringSlice(key string) []string {
|
||||
val, ok := u.c[key]
|
||||
if !ok || val == nil {
|
||||
return nil
|
||||
}
|
||||
return val.([]string)
|
||||
}
|
||||
|
||||
func (u Cli) GlobalInt(key string) int {
|
||||
val, ok := u.c[key]
|
||||
if !ok || val == nil {
|
||||
return 0
|
||||
}
|
||||
return val.(int)
|
||||
}
|
||||
|
||||
func (u Cli) GlobalIntSlice(key string) []int {
|
||||
val, ok := u.c[key]
|
||||
if !ok || val == nil {
|
||||
return nil
|
||||
}
|
||||
return val.([]int)
|
||||
}
|
||||
|
||||
func (u Cli) GlobalInt64(key string) int64 {
|
||||
val, ok := u.c[key]
|
||||
if !ok || val == nil {
|
||||
return 0
|
||||
}
|
||||
return val.(int64)
|
||||
}
|
||||
|
||||
func (u Cli) GlobalInt64Slice(key string) []int64 {
|
||||
val, ok := u.c[key]
|
||||
if !ok || val == nil {
|
||||
return nil
|
||||
}
|
||||
return val.([]int64)
|
||||
}
|
||||
|
||||
func (u Cli) Duration(key string) time.Duration {
|
||||
val, ok := u.c[key]
|
||||
if !ok || val == nil {
|
||||
return 0
|
||||
}
|
||||
return val.(time.Duration)
|
||||
}
|
||||
@@ -18,6 +18,7 @@ package urfavecli
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/urfave/cli"
|
||||
|
||||
@@ -107,3 +108,7 @@ func (u Cli) GlobalInt64(key string) int64 {
|
||||
func (u Cli) GlobalInt64Slice(key string) []int64 {
|
||||
return u.c.GlobalInt64Slice(key)
|
||||
}
|
||||
|
||||
func (u Cli) Duration(key string) time.Duration {
|
||||
return u.c.Duration(key)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user