-
Notifications
You must be signed in to change notification settings - Fork 9
/
configuration.go
48 lines (40 loc) · 1.75 KB
/
configuration.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package configuration
import (
"fmt"
"net/http"
"github.com/forestnode-io/oneshot/v2/pkg/flagargs"
"github.com/forestnode-io/oneshot/v2/pkg/flags"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
type Configuration struct {
ArchiveMethod string `mapstructure:"archivemethod" yaml:"archivemethod"`
NoDownload bool `mapstructure:"nodownload" yaml:"nodownload"`
MIME string `mapstructure:"mime" yaml:"mime"`
Name string `mapstructure:"name" yaml:"name"`
StatusCode int `mapstructure:"statuscode" yaml:"statuscode"`
Header flagargs.HTTPHeader `mapstructure:"header" yaml:"header"`
}
func SetFlags(cmd *cobra.Command) {
fs := pflag.NewFlagSet("send flags", pflag.ExitOnError)
defer cmd.Flags().AddFlagSet(fs)
flags.StringP(fs, "cmd.send.archivemethod", "archive-method", "a", `Which archive method to use when sending directories.`)
flags.BoolP(fs, "cmd.send.nodownload", "no-download", "D", "Do not allow the client to download the file.")
flags.StringP(fs, "cmd.send.mime", "mime", "m", `MIME type of file presented to client.`)
flags.StringP(fs, "cmd.send.name", "name", "n", `Name of file presented to client if downloading.`)
flags.Int(fs, "cmd.send.statuscode", "status-code", "HTTP status code to send to client.")
flags.StringSliceP(fs, "cmd.send.header", "header", "H", `Header to send to client. Can be specified multiple times.
Format: <HEADER NAME>=<HEADER VALUE>`)
cobra.AddTemplateFunc("sendFlags", func() *pflag.FlagSet {
return fs
})
}
func (c *Configuration) Validate() error {
if t := http.StatusText(c.StatusCode); t == "" {
return fmt.Errorf("invalid status code")
}
return nil
}
func (c *Configuration) Hydrate() error {
return nil
}