Skip to content

Commit

Permalink
Config file flag (#3615)
Browse files Browse the repository at this point in the history
* add config-file flag for launch

* add check for config-file extension

* update to use existing appconfig flag

* fix filename issues

* use configFile
  • Loading branch information
fliepeltje committed Jun 12, 2024
1 parent 4fefe6b commit eba3578
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions internal/command/launch/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func New() (cmd *cobra.Command) {
flag.Region(),
flag.Org(),
flag.NoDeploy(),
flag.AppConfig(),
flag.Bool{
Name: "generate-name",
Description: "Always generate a name for the app, without prompting",
Expand Down
15 changes: 12 additions & 3 deletions internal/command/launch/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/superfly/fly-go/flaps"
"github.com/superfly/flyctl/internal/appconfig"
"github.com/superfly/flyctl/internal/flag"
"github.com/superfly/flyctl/internal/flag/flagnames"
"github.com/superfly/flyctl/internal/flapsutil"
"github.com/superfly/flyctl/internal/flyutil"
"github.com/superfly/flyctl/internal/tracing"
Expand Down Expand Up @@ -82,12 +83,20 @@ func (state *launchState) Launch(ctx context.Context) error {
}

// Finally write application configuration to fly.toml
configPath := state.configPath
configDir, configFile := filepath.Split(state.configPath)
configFileOverride := flag.GetString(ctx, flagnames.AppConfigFilePath)
if configFileOverride != "" {
configFile = configFileOverride
}

// Resolve config format flags if applicable
if flag.GetBool(ctx, "json") {
configPath = strings.TrimSuffix(configPath, filepath.Ext(configPath)) + ".json"
configFile = strings.TrimSuffix(configFile, filepath.Ext(configFile)) + ".json"
} else if flag.GetBool(ctx, "yaml") {
configPath = strings.TrimSuffix(configPath, filepath.Ext(configPath)) + ".yaml"
configFile = strings.TrimSuffix(configFile, filepath.Ext(configFile)) + ".yaml"
}

configPath := filepath.Join(configDir, configFile)
state.appConfig.SetConfigFilePath(configPath)
if err := state.appConfig.WriteToDisk(ctx, configPath); err != nil {
return err
Expand Down

0 comments on commit eba3578

Please sign in to comment.