func service(c *config.Config, q *registry.Queue) error { name := q.NextTask() if name == "" { return fmt.Errorf("first arg should be the name of the service") } q.RemoveNextTask() module := q.NextTask() if module == "" { return fmt.Errorf("second arg should be the module of the service") } q.RemoveNextTask() data := &serviceData{ Name: name, Module: module, Filename: filepath.Join(strings.Split(module, ".")...), } if err := writeServiceFile(data); err != nil { return fmt.Errorf("write service failed: %s", err) } if err := writeServiceTestFile(data); err != nil { return fmt.Errorf("write service test failed: %s", err) } return nil }
func doForm(c *config.Config, q *registry.Queue, mode string) error { if !templates.IsRegistered(mode) { return fmt.Errorf("unrecognized template mode: %s", mode) } templates.SetMode(mode) filename := q.NextTask() if filename == "" { return fmt.Errorf("validator filename not passed as an argument") } q.RemoveNextTask() form, err := parseForm(filename) if err != nil { return fmt.Errorf("parse form failed: %s", err) } result := strings.Replace(form.Build(), "'", `'"'"'`, -1) args := []string{ "-c", fmt.Sprintf(`echo -n '%s' | xsel -bi`, result), } output, err := utils.Exec("bash", args) if err != nil { fmt.Println(output) return fmt.Errorf("bash error: %s", err) } return nil }
func push(c *config.Config, q *registry.Queue) error { scriptsPath := utils.PackagePath(selfPkg) host := c.GetRequired("push") // FTP User & password user := q.NextTask() if user == "" { return fmt.Errorf("ftp user required as the first argument") } q.RemoveNextTask() password, err := gopass.GetPass(fmt.Sprintf("Enter \"%s\" password: "******"cannot read password: %s", err) } if password == "" { return fmt.Errorf("ftp password is required") } // Hash local files log.Printf("Hashing local files... ") localHashes, err := hashLocalFiles() if err != nil { return fmt.Errorf("hash local files failed: %s", err) } log.Printf("Hashing local files... %s[SUCCESS]%s\n", colors.Green, colors.Reset) // Hash remote files log.Printf("Hashing remote files... ") remoteHashes, err := retrieveRemoteHashes(scriptsPath, user, password, host) if err != nil { return fmt.Errorf("retrieve remote hashes failed: %s", err) } log.Printf("Hashing remote files... %s[SUCCESS]%s\n", colors.Green, colors.Reset) if err := saveLocalHashes(localHashes); err != nil { return fmt.Errorf("save local hashes failed: %s", err) } // Prepare FTP commands log.Printf("Preparing FTP commands... ") if err := prepareFTPCommands(localHashes, remoteHashes); err != nil { return fmt.Errorf("prepare FTP commands failed: %s", err) } log.Printf("Preparing FTP commands... %s[SUCCESS]%s\n", colors.Green, colors.Reset) // Upload files log.Printf("Uploading files... ") if err := uploadFiles(scriptsPath, user, password, host); err != nil { return fmt.Errorf("uploading files failed: %s", err) } log.Printf("Uploading files... %s[SUCCESS]%s\n", colors.Green, colors.Reset) return nil }
func controller(c *config.Config, q *registry.Queue) error { name := q.NextTask() if name == "" { return fmt.Errorf("first arg should be the name of the controller") } q.RemoveNextTask() if !strings.Contains(name, "Ctrl") { name = name + "Ctrl" } module := q.NextTask() if module == "" { return fmt.Errorf("second arg should be the module of the controller") } q.RemoveNextTask() route := q.NextTask() q.RemoveNextTask() data := &controllerData{ Name: name, Module: module, Route: route, Filename: filepath.Join(strings.Split(module, ".")...), AppPath: c.GetDefault("paths.app", filepath.Join("app", "scripts", "app.js")), } if err := writeControllerFile(data); err != nil { return fmt.Errorf("write controller failed: %s", err) } if err := writeControllerTestFile(data); err != nil { return fmt.Errorf("write controller test failed: %s", err) } if err := writeControllerViewFile(data); err != nil { return fmt.Errorf("write view failed: %s", err) } if route != "" { if err := writeControllerRouteFile(data); err != nil { return fmt.Errorf("write route failed: %s", err) } } return nil }