Exemplo n.º 1
0
func (c *GenerateCommand) Run(args []string) int {
	if _, err := utils.AreWeInAppRootDir(); err != nil {
		return 1
	}

	if len(args) < 2 {
		fmt.Printf("%v", c.Help())
		return 1
	}

	subcommand := args[0]

	//assume that we're in the base polka directory
	//confirm that by checking to see if ./app/ exists
	if currentDir, err := os.Getwd(); err == nil {
		//TODO check to see if ./app/ exists
		switch subcommand {
		case "endpoint":
			MakeAllEndpoints(currentDir, args[1])
		case "integration":
			log.Println("generating integrations are not implemented yet")
		}
		return 0
	}
	return 1
}
Exemplo n.º 2
0
func LoadProjectConfig() (ProjectConfig, error) {
	var config ProjectConfig
	if appDir, err := utils.AreWeInAppRootDir(); err == nil {
		//attempt to load the old file

		log.Println("loaded existing app.json")
		abspath := fmt.Sprintf("%s/config/app.json", appDir)
		configFile, err := os.Open(abspath)
		defer configFile.Close()
		if err == nil {
			jsonParser := json.NewDecoder(configFile)
			if err = jsonParser.Decode(&config); err == nil {
				return config, err
			} else {
				return config, err
			}
		} else {
			//ok, that failed, let's make a new one and return it.  Not that it is **not saved**.
			return config, nil
		}
	} else {
		//ok, that failed, let's make a new one and return it.  Not that it is **not saved**.
		return config, err
	}
}
Exemplo n.º 3
0
func (c *DestroyCommand) Run(args []string) int {
	if _, err := utils.AreWeInAppRootDir(); err != nil {

		return 1
	}

	return 1
}
Exemplo n.º 4
0
//Save this project config in config/app.json.  Always overwrites the previous file.
func (p *ProjectConfig) Save() {
	if appDir, err := utils.AreWeInAppRootDir(); err == nil {
		fileName := fmt.Sprintf("%s/config/app.json", appDir)
		if b, err := json.MarshalIndent(p, "", "  "); err == nil {

			if err := ioutil.WriteFile(fileName, b, 0644); err != nil {
				log.Println(err)
			}
		}
	}
}
Exemplo n.º 5
0
func handleCommandOutsideOfProjectDir(args []string) {
	if len(args) > 0 {
		switch args[0] {
		case "new":
			//do nothing in the case of the "new" command
		default:
			if _, err := utils.AreWeInAppRootDir(); err == nil {
				//otherwise, make sure we have the AppConfig setup
			} else {
				log.Println(err)
			}
		}
	}
}
Exemplo n.º 6
0
//Create a lambda_config.json file that can be used as part of the input into AWS.
//conceptName should be something like "todo" or anything else anything else that might exist under app/endpoint/{conceptName}
//dir should be ??
func Create(conceptName string, dir string) error {
	//I believe we should be in the app root directory
	appRootDir, err := utils.AreWeInAppRootDir()
	if err != nil {
		return err
	}
	//so we can create the config for conceptName as
	//./config/{dir}/{conceptName}_lambdaconfig.json
	configDir := fmt.Sprintf("%v/config/%v", appRootDir, conceptName)
	log.Printf("configDir = %v \n", configDir)
	filename := fmt.Sprintf("%v/%v_lambdaconfig.json", configDir, dir)
	log.Printf("configFilename = %v \n", filename)

	if err := os.MkdirAll(configDir, 0777); err != nil {
		return err
	}
	//we made configDir and all parents as needed
	configFile, err := os.Create(filename)
	if err != nil {
		return err
	}
	//TODO move default config ?
	defaultConfig := LambdaConfig{
		Name:      "blah", //TODO this needs to be a better name
		RAM:       1024,   //TODO make this configurable
		Timeout:   10,
		AWSRegion: "us-east-1", //TODO make this configurable
	}

	b, err := json.MarshalIndent(defaultConfig, "", "  ")
	if err != nil {
		return err
	}
	//else we're good
	configFile.Write(b)

	return nil
}