-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec75382
commit 012273d
Showing
3 changed files
with
78 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package generate | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
|
||
"github.com/aquaproj/aqua/pkg/config/aqua" | ||
"github.com/spf13/afero" | ||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
type outputter struct { | ||
stdout io.Writer | ||
fs afero.Fs | ||
} | ||
|
||
type OutputParam struct { | ||
Insert bool | ||
Dest string | ||
List []*aqua.Package | ||
ConfigFilePath string | ||
} | ||
|
||
func (out *outputter) Output(param *OutputParam) error { | ||
if !param.Insert && param.Dest == "" { | ||
if err := yaml.NewEncoder(out.stdout).Encode(param.List); err != nil { | ||
return fmt.Errorf("output generated package configuration: %w", err) | ||
} | ||
return nil | ||
} | ||
|
||
if param.Dest != "" { | ||
if _, err := out.fs.Stat(param.Dest); err != nil { | ||
if err := afero.WriteFile(out.fs, param.Dest, []byte("packages:\n\n"), 0o644); err != nil { //nolint:gomnd | ||
return fmt.Errorf("create a file: %w", err) | ||
} | ||
} | ||
return out.generateInsert(param.Dest, param.List) | ||
} | ||
|
||
return out.generateInsert(param.ConfigFilePath, param.List) | ||
} |