Skip to content

Commit c856558

Browse files
committed
feat: Add override file flag to init command (closes #184)
Signed-off-by: Mayowa <[email protected]>
1 parent 52ea718 commit c856558

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

cmd/init.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"encoding/hex"
2323
"errors"
2424
"fmt"
25+
"os"
2526
"path/filepath"
2627
"regexp"
2728
"strconv"
@@ -41,7 +42,7 @@ var promptNames bool
4142
var ffNameValidator = regexp.MustCompile(`^[0-9a-zA-Z]([0-9a-zA-Z._-]{0,62}[0-9a-zA-Z])?$`)
4243

4344
var stackNameInvalidRegex = regexp.MustCompile(`[^-_a-z0-9]`)
44-
45+
var overrideFile string
4546
var initCmd = &cobra.Command{
4647
Use: "init [stack_name] [member_count]",
4748
Short: "Create a new FireFly local dev stack",
@@ -60,6 +61,26 @@ var initCmd = &cobra.Command{
6061
}
6162
return err
6263
}
64+
if overrideFile != "" {
65+
// 1. Check if the file the user provided exists
66+
if _, err := os.Stat(overrideFile); err != nil {
67+
return fmt.Errorf("could not find custom override file: %s", err)
68+
}
69+
70+
destPath := filepath.Join(stackManager.Stack.StackDir, "docker-compose.override.yml")
71+
// 3. Copy the file
72+
input, err := os.ReadFile(overrideFile)
73+
if err != nil {
74+
return fmt.Errorf("could not read override file: %s", err)
75+
}
76+
77+
err = os.WriteFile(destPath, input, 0644)
78+
if err != nil {
79+
return fmt.Errorf("could not write override file: %s", err)
80+
}
81+
82+
fmt.Printf("Copied custom override file to: %s\n", destPath)
83+
}
6384
fmt.Printf("Stack '%s' created!\nTo start your new stack run:\n\n%s start %s\n", initOptions.StackName, rootCmd.Use, initOptions.StackName)
6485
fmt.Printf("\nYour docker compose file for this stack can be found at: %s\n\n", filepath.Join(stackManager.Stack.StackDir, "docker-compose.yml"))
6586
return nil
@@ -317,6 +338,7 @@ func init() {
317338
initCmd.PersistentFlags().IntVarP(&initOptions.ExternalProcesses, "external", "e", 0, "Manage a number of FireFly core processes outside of the docker-compose stack - useful for development and debugging")
318339
initCmd.PersistentFlags().StringVarP(&initOptions.FireFlyVersion, "release", "r", "latest", fmt.Sprintf("Select the FireFly release version to use. Options are: %v", fftypes.FFEnumValues(types.ReleaseChannelSelection)))
319340
initCmd.PersistentFlags().StringVarP(&initOptions.ManifestPath, "manifest", "m", "", "Path to a manifest.json file containing the versions of each FireFly microservice to use. Overrides the --release flag.")
341+
initCmd.Flags().StringVarP(&overrideFile, "file", "f", "", "Custom docker-compose.override.yml file to copy")
320342
initCmd.PersistentFlags().BoolVar(&promptNames, "prompt-names", false, "Prompt for org and node names instead of using the defaults")
321343
initCmd.PersistentFlags().BoolVar(&initOptions.PrometheusEnabled, "prometheus-enabled", false, "Enables Prometheus metrics exposition and aggregation to a shared Prometheus server")
322344
initCmd.PersistentFlags().BoolVar(&initOptions.SandboxEnabled, "sandbox-enabled", true, "Enables the FireFly Sandbox to be started with your FireFly stack")

0 commit comments

Comments
 (0)