@@ -50,6 +50,7 @@ var _ plugin.EditSubcommand = &editSubcommand{}
5050type editSubcommand struct {
5151 config config.Config
5252 force bool
53+ inputDir string
5354 manifestsFile string
5455 outputDir string
5556}
@@ -76,6 +77,12 @@ distribution of your project. When enabled, adds Helm helpers targets to Makefil
7677# Generate from custom manifests to custom output directory
7778 %[1]s edit --plugins=%[2]s --manifests=manifests/install.yaml --output-dir=helm-charts
7879
80+ # Generate chart from a different project directory
81+ %[1]s edit --plugins=%[2]s --input-dir=./path/to/project
82+
83+ # Use custom manifests file (resolved relative to input-dir)
84+ %[1]s edit --plugins=%[2]s --input-dir=./path/to/project --manifests=custom/install.yaml
85+
7986# Typical workflow:
8087 make build-installer # Generate dist/install.yaml with latest changes
8188 %[1]s edit --plugins=%[2]s # Generate/update Helm chart in dist/chart/
@@ -103,8 +110,11 @@ The generated chart structure mirrors your config/ directory:
103110
104111func (p * editSubcommand ) BindFlags (fs * pflag.FlagSet ) {
105112 fs .BoolVar (& p .force , "force" , false , "if true, regenerates all the files" )
113+ fs .StringVar (& p .inputDir , "input-dir" , "" ,
114+ "path to the directory containing the PROJECT file and manifests (defaults to current directory)" )
106115 fs .StringVar (& p .manifestsFile , "manifests" , DefaultManifestsFile ,
107- "path to the YAML file containing Kubernetes manifests from kustomize output" )
116+ "path to the YAML file containing Kubernetes manifests from kustomize output " +
117+ "(resolved relative to input-dir if not absolute)" )
108118 fs .StringVar (& p .outputDir , "output-dir" , DefaultOutputDir , "output directory for the generated Helm chart" )
109119}
110120
@@ -114,14 +124,38 @@ func (p *editSubcommand) InjectConfig(c config.Config) error {
114124}
115125
116126func (p * editSubcommand ) Scaffold (fs machinery.Filesystem ) error {
127+ // Resolve input directory (defaults to current working directory)
128+ if p .inputDir == "" {
129+ cwd , err := os .Getwd ()
130+ if err != nil {
131+ return fmt .Errorf ("failed to get current working directory: %w" , err )
132+ }
133+ p .inputDir = cwd
134+ }
135+
136+ // Convert input directory to absolute path if needed
137+ if ! filepath .IsAbs (p .inputDir ) {
138+ absInputDir , err := filepath .Abs (p .inputDir )
139+ if err != nil {
140+ return fmt .Errorf ("failed to resolve input directory %q: %w" , p .inputDir , err )
141+ }
142+ p .inputDir = absInputDir
143+ }
144+
145+ // Resolve manifests path relative to input directory if not absolute
146+ manifestsPath := p .manifestsFile
147+ if ! filepath .IsAbs (manifestsPath ) {
148+ manifestsPath = filepath .Join (p .inputDir , manifestsPath )
149+ }
150+
117151 // If using default manifests file, ensure it exists by running make build-installer
118152 if p .manifestsFile == DefaultManifestsFile {
119- if err := p .ensureManifestsExist (); err != nil {
120- slog .Warn ("Failed to generate default manifests file" , "error" , err , "file" , p . manifestsFile )
153+ if err := p .ensureManifestsExist (manifestsPath ); err != nil {
154+ slog .Warn ("Failed to generate default manifests file" , "error" , err , "file" , manifestsPath )
121155 }
122156 }
123157
124- scaffolder := scaffolds .NewKustomizeHelmScaffolder (p .config , p .force , p . manifestsFile , p .outputDir )
158+ scaffolder := scaffolds .NewKustomizeHelmScaffolder (p .config , p .force , manifestsPath , p .outputDir )
125159 scaffolder .InjectFS (fs )
126160 err := scaffolder .Scaffold ()
127161 if err != nil {
@@ -175,7 +209,7 @@ func (p *editSubcommand) Scaffold(fs machinery.Filesystem) error {
175209 if isFirstRun {
176210 slog .Info ("adding Helm deployment targets to Makefile..." )
177211 // Extract namespace from manifests for accurate Makefile generation
178- namespace := p .extractNamespaceFromManifests ()
212+ namespace := p .extractNamespaceFromManifests (manifestsPath )
179213 if err := p .addHelmMakefileTargets (namespace ); err != nil {
180214 slog .Warn ("failed to add Helm targets to Makefile" , "error" , err )
181215 }
@@ -185,8 +219,20 @@ func (p *editSubcommand) Scaffold(fs machinery.Filesystem) error {
185219}
186220
187221// ensureManifestsExist runs make build-installer to generate the default manifests file
188- func (p * editSubcommand ) ensureManifestsExist () error {
189- slog .Info ("Generating default manifests file" , "file" , p .manifestsFile )
222+ func (p * editSubcommand ) ensureManifestsExist (manifestsPath string ) error {
223+ slog .Info ("Generating default manifests file" , "file" , manifestsPath )
224+
225+ // Change to input directory to run make commands
226+ originalDir , err := os .Getwd ()
227+ if err != nil {
228+ return fmt .Errorf ("failed to get current directory: %w" , err )
229+ }
230+ if err := os .Chdir (p .inputDir ); err != nil {
231+ return fmt .Errorf ("failed to change to input directory %q: %w" , p .inputDir , err )
232+ }
233+ defer func () {
234+ _ = os .Chdir (originalDir )
235+ }()
190236
191237 // Run the required make targets to generate the manifests file
192238 targets := []string {"manifests" , "generate" , "build-installer" }
@@ -197,11 +243,11 @@ func (p *editSubcommand) ensureManifestsExist() error {
197243 }
198244
199245 // Verify the file was created
200- if _ , err := os .Stat (p . manifestsFile ); err != nil {
201- return fmt .Errorf ("manifests file %s was not created: %w" , p . manifestsFile , err )
246+ if _ , err := os .Stat (manifestsPath ); err != nil {
247+ return fmt .Errorf ("manifests file %s was not created: %w" , manifestsPath , err )
202248 }
203249
204- slog .Info ("Successfully generated manifests file" , "file" , p . manifestsFile )
250+ slog .Info ("Successfully generated manifests file" , "file" , manifestsPath )
205251 return nil
206252}
207253
@@ -265,17 +311,17 @@ func (p *editSubcommand) addHelmMakefileTargets(namespace string) error {
265311
266312// extractNamespaceFromManifests parses the manifests file to extract the manager namespace.
267313// Returns projectName-system if manifests don't exist or namespace not found.
268- func (p * editSubcommand ) extractNamespaceFromManifests () string {
314+ func (p * editSubcommand ) extractNamespaceFromManifests (manifestsPath string ) string {
269315 // Default to project-name-system pattern
270316 defaultNamespace := p .config .GetProjectName () + "-system"
271317
272318 // If manifests file doesn't exist, use default
273- if _ , err := os .Stat (p . manifestsFile ); os .IsNotExist (err ) {
319+ if _ , err := os .Stat (manifestsPath ); os .IsNotExist (err ) {
274320 return defaultNamespace
275321 }
276322
277323 // Parse the manifests to get the namespace
278- file , err := os .Open (p . manifestsFile )
324+ file , err := os .Open (manifestsPath )
279325 if err != nil {
280326 return defaultNamespace
281327 }
0 commit comments