func (h *HttpGet) setTo(args haiconf.CommandArgs) error { t, _ := haiconf.CheckString("To", args) if len(t) == 0 { return haiconf.NewArgError("To must be provided", args) } if !utils.HasFileName(t) { return haiconf.NewArgError(t+" must be a file name", args) } dir := filepath.Dir(t) id, err := utils.IsDir(dir) if err != nil { return haiconf.NewArgError(err.Error(), args) } if !id { return haiconf.NewArgError(dir+" is not a directory", args) } h.To = t return nil }
func (c *Cron) setSchedule(args haiconf.CommandArgs) error { _, present := args["Schedule"] if !present { return haiconf.NewArgError("Schedule must be provided", args) } schedule, err := utils.ToStringMap(args["Schedule"].(map[string]interface{})) if err != nil { return err } predefined, err := c.checkPredefined(schedule) if err != nil { return err } if len(predefined) > 0 { c.Schedule = PREDEFINED_SCHEDULES[predefined] return nil } nonPredefined, err := c.checkNonPredefined(schedule) if err != nil { return err } c.Schedule = nonPredefined return nil }
func (h *HttpGet) setFrom(args haiconf.CommandArgs) error { f, _ := haiconf.CheckString("From", args) if len(f) == 0 { return haiconf.NewArgError("From must be provided", args) } f = strings.ToLower(f) if f[:7] == "http://" || f[:8] == "https://" { h.From = f return nil } return haiconf.NewArgError("From must be http or https", args) }
func (ag *AptGet) setPackages(args haiconf.CommandArgs) error { pl, _ := haiconf.CheckStringList("Packages", args) if len(pl) > 0 { ag.Packages = stringutils.RemoveDuplicates(pl) return nil } pfs, _ := haiconf.CheckAbsolutePath("PackagesFromSource", args) if pfs != "" { buff, err := ioutil.ReadFile(pfs) if err != nil { return err } nlSplit := func(r rune) bool { if r == '\n' { return true } return false } pkgs := strings.FieldsFunc(string(buff), nlSplit) ag.Packages = stringutils.RemoveDuplicates(pkgs) return nil } msg := "You must provide a value for either Packages or PackagesFromSource" return haiconf.NewArgError(msg, args) }
func (t *TarGz) setSource(args haiconf.CommandArgs) error { s, _ := haiconf.CheckString("Source", args) if len(s) == 0 { return haiconf.NewArgError("Source must be provided", args) } f, err := os.Open(s) if err != nil { if os.IsNotExist(err) { return haiconf.NewArgError("Source does not exist", args) } } defer f.Close() t.Source = s return nil }
func (t *UnTarGz) setDest(args haiconf.CommandArgs) error { d, _ := haiconf.CheckString("Dest", args) if len(d) == 0 { return haiconf.NewArgError("Dest must be provided", args) } id, err := utils.IsDir(d) if err != nil { return err } if !id { return haiconf.NewArgError(d+" is not a directory", args) } t.Dest = d return nil }
func (t *UnTarGz) setSource(args haiconf.CommandArgs) error { s, _ := haiconf.CheckString("Source", args) if len(s) == 0 { return haiconf.NewArgError("Source must be provided", args) } fi, err := os.Stat(s) if err != nil { return err } if !fi.Mode().IsRegular() { return haiconf.NewArgError(s+" is not a file", args) } t.Source = s return nil }
func (t *TarGz) setDest(args haiconf.CommandArgs) error { d, _ := haiconf.CheckString("Dest", args) if len(d) == 0 { return haiconf.NewArgError("Dest must be provided", args) } if !strings.HasSuffix(d, ".tar.gz") { return haiconf.NewArgError("No tarball name provided", args) } id, err := utils.IsDir(filepath.Dir(d)) if err != nil { return err } if !id { return haiconf.NewArgError(d+" is not a directory", args) } t.Dest = d return nil }