2017-03-25 02:41:36 +00:00
|
|
|
package webcmd
|
|
|
|
|
2017-03-27 07:03:19 +00:00
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"errors"
|
|
|
|
)
|
|
|
|
|
2017-03-25 02:41:36 +00:00
|
|
|
type ParamType int
|
|
|
|
|
|
|
|
const (
|
|
|
|
PARAMTYPE_CONST ParamType = 0
|
|
|
|
PARAMTYPE_STRING ParamType = 1
|
|
|
|
PARAMTYPE_OPTIONAL ParamType = 2
|
|
|
|
// bool 1/0
|
|
|
|
// list
|
|
|
|
// k/v list
|
|
|
|
// file upload (temporary path passed to binary)
|
|
|
|
// nested parse subgroup (e.g. ffmpeg filters)
|
|
|
|
// one optional to control a whole subgroup (e.g. --timeout 4)
|
|
|
|
// String validations (regexp, min-length, ...)
|
|
|
|
)
|
|
|
|
|
|
|
|
type InputParam struct {
|
2017-03-27 07:03:19 +00:00
|
|
|
Description string `json:",omitempty"` // only used for editable parameters
|
2017-03-25 02:41:36 +00:00
|
|
|
ParamType ParamType
|
|
|
|
Value string
|
|
|
|
}
|
|
|
|
|
2017-03-27 08:49:05 +00:00
|
|
|
func (ip *InputParam) UnmarshalJSON(b []byte) error {
|
|
|
|
switch b[0] {
|
|
|
|
case '"':
|
2017-03-27 07:03:19 +00:00
|
|
|
ip.Description = ""
|
|
|
|
ip.ParamType = PARAMTYPE_CONST
|
2017-03-27 08:49:05 +00:00
|
|
|
tmp := ""
|
|
|
|
err := json.Unmarshal(b, &tmp)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
ip.Value = tmp
|
2017-03-27 07:03:19 +00:00
|
|
|
|
2017-03-27 08:49:05 +00:00
|
|
|
case '{':
|
2017-03-27 07:03:19 +00:00
|
|
|
read := struct {
|
|
|
|
Description string `json:",omitempty"`
|
|
|
|
ParamType ParamType
|
|
|
|
Value string
|
|
|
|
}{}
|
|
|
|
err := json.Unmarshal(b, &read)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
*ip = read
|
|
|
|
return nil
|
|
|
|
|
2017-03-27 08:49:05 +00:00
|
|
|
default:
|
2017-03-27 07:03:19 +00:00
|
|
|
return errors.New("Malformed InputParam")
|
|
|
|
}
|
2017-03-27 08:49:05 +00:00
|
|
|
|
|
|
|
return nil
|
2017-03-27 07:03:19 +00:00
|
|
|
}
|
|
|
|
|
2017-03-25 02:41:36 +00:00
|
|
|
type CommandConfig struct {
|
2017-03-25 02:58:55 +00:00
|
|
|
Title string
|
|
|
|
WorkingDir string // default empty-string: getcwd()
|
2017-03-27 07:03:19 +00:00
|
|
|
Execution []InputParam // Can be unmarshalled using plain strings
|
2017-03-25 02:41:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type AppConfig struct {
|
2017-03-25 02:55:48 +00:00
|
|
|
ListenAddress string
|
|
|
|
AppTitle string
|
|
|
|
MaxHistoryLines int // default zero: unlimited history for each command
|
|
|
|
Commands []CommandConfig
|
2017-03-25 02:41:36 +00:00
|
|
|
}
|