Skip to content

Commit

Permalink
Allow multiple projects in one set of prompts (#579)
Browse files Browse the repository at this point in the history
* Helps if your change affects multiple projects without being
too inconvenient if not.
* Add an example for projects.
* Add a link to npm package in nodejs install docs
* Modify project command flag to use --projects over --project
* Release v1.16.0
  • Loading branch information
miniscruff authored Nov 12, 2023
1 parent c65f1e9 commit b7d2abf
Show file tree
Hide file tree
Showing 19 changed files with 1,469 additions and 1,061 deletions.
6 changes: 6 additions & 0 deletions .changes/v1.16.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## v1.16.0 on 2023-11-12

### Changed

* [#571](https://github.com/miniscruff/changie/issues/571) Project prompt is now a multichoose prompt to allow one change to affect multiple projects without repeating the prompts
* [#571](https://github.com/miniscruff/changie/issues/571) Project command line argument for new is now a list of projects and uses --projects instead of --project
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html),
and is generated by [itself](https://github.com/miniscruff/changie).

## v1.16.0 on 2023-11-12

### Changed

* [#571](https://github.com/miniscruff/changie/issues/571) Project prompt is now a multichoose prompt to allow one change to affect multiple projects without repeating the prompts
* [#571](https://github.com/miniscruff/changie/issues/571) Project command line argument for new is now a list of projects and uses --projects instead of --project

## v1.15.1 on 2023-10-29

### Fixed
Expand Down
91 changes: 45 additions & 46 deletions cmd/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type New struct {

// cli args
DryRun bool
Project string
Projects []string
Component string
Kind string
Body string
Expand Down Expand Up @@ -60,11 +60,11 @@ Each version is merged together for the overall project changelog.`,
false,
"Print new fragment instead of writing to disk",
)
cmd.Flags().StringVarP(
&n.Project,
"project", "j",
"",
"(Preview) Set the change project key without a prompt",
cmd.Flags().StringSliceVarP(
&n.Projects,
"projects", "j",
[]string{},
"(Preview) Set the change projects without a prompt",
)
cmd.Flags().StringVarP(
&n.Component,
Expand Down Expand Up @@ -113,57 +113,56 @@ func (n *New) Run(cmd *cobra.Command, args []string) error {
return err
}

change := core.Change{
Project: n.Project,
Component: n.Component,
Kind: n.Kind,
Body: n.Body,
Custom: customValues,
Env: config.EnvVars(),
}

err = change.AskPrompts(core.PromptContext{
Config: config,
prompts := &core.Prompts{
StdinReader: n.InOrStdin(),
BodyEditor: n.BodyEditor,
Projects: n.Projects,
Component: n.Component,
Kind: n.Kind,
Body: n.Body,
TimeNow: n.TimeNow,
Config: config,
Customs: customValues,
CreateFiler: os.Create,
EditorCmdBuilder: core.BuildCommand,
})
}

changes, err := prompts.BuildChanges()
if err != nil {
return err
}

change.Time = n.TimeNow()

var writer io.Writer

if n.DryRun {
writer = n.OutOrStdout()
} else {
var fragmentWriter strings.Builder
fileErr := n.TemplateCache.Execute(config.FragmentFileFormat, &fragmentWriter, change)
if fileErr != nil {
return fileErr
}
fragmentWriter.WriteString(".yaml")
outputFilename := fragmentWriter.String()

// Sanatize the filename to remove invalid characters such as slashes
replacer := strings.NewReplacer("/", "-", "\\", "-")
outputFilename = replacer.Replace(outputFilename)

outputPath := filepath.Join(config.ChangesDir, config.UnreleasedDir, outputFilename)
newFile, fileErr := n.CreateFile(outputPath)
if fileErr != nil {
return fileErr
for _, change := range changes {
var writer io.Writer

if n.DryRun {
writer = n.OutOrStdout()
} else {
var fragmentWriter strings.Builder
fileErr := n.TemplateCache.Execute(config.FragmentFileFormat, &fragmentWriter, change)
if fileErr != nil {
return fileErr
}
fragmentWriter.WriteString(".yaml")
outputFilename := fragmentWriter.String()

// Sanatize the filename to remove invalid characters such as slashes
replacer := strings.NewReplacer("/", "-", "\\", "-")
outputFilename = replacer.Replace(outputFilename)

outputPath := filepath.Join(config.ChangesDir, config.UnreleasedDir, outputFilename)
newFile, fileErr := n.CreateFile(outputPath)
if fileErr != nil {
return fileErr
}

defer newFile.Close()

writer = newFile
}

defer newFile.Close()

writer = newFile
_, err = change.WriteTo(writer)
}

_, err = change.WriteTo(writer)

return err
}
Loading

0 comments on commit b7d2abf

Please sign in to comment.