Skip to content

Commit

Permalink
fix dottie update
Browse files Browse the repository at this point in the history
  • Loading branch information
jippi committed Feb 5, 2024
1 parent db453d7 commit 80b8f30
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
14 changes: 8 additions & 6 deletions cmd/cmd_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var updateCommand = &cli.Command{

// Copy source to "new"
fmt.Print("Copying .env.source into .env.merged")
if err := Copy(".env.merged", ".env.source"); err != nil {
if err := Copy(".env.source", ".env.merged"); err != nil {
return err
}
fmt.Println(" ✅")
Expand All @@ -67,17 +67,19 @@ var updateCommand = &cli.Command{
// Take current assignments and set them in the new doc
fmt.Println("Updating .env.merged with key/value pairs from .env")
for _, stmt := range env.Assignments() {
if stmt.Active {
if !stmt.Active {
continue
}

changed, err := mergedEnv.Set(&ast.Assignment{Name: stmt.Name, Literal: stmt.Literal}, ast.SetOptions{SkipIfSame: true})
changed, err := mergedEnv.Set(stmt, ast.SetOptions{SkipIfSame: true, ErrorIfMissing: true})
if err != nil {
return err
fmt.Println(" ❌", err.Error())

continue
}

if changed {
fmt.Println(" ✅", stmt.Name)
fmt.Println(" ✅", fmt.Sprintf("Key [%s] was successfully updated", stmt.Name))
}
}

Expand All @@ -88,7 +90,7 @@ var updateCommand = &cli.Command{
},
}

func Copy(dst, src string) error {
func Copy(src, dst string) error {
srcF, err := os.Open(src)
if err != nil {
return err
Expand Down
18 changes: 9 additions & 9 deletions pkg/ast/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,23 @@ func (d *Document) statementNode() {
}

func (d *Document) Assignments() []*Assignment {
var values []*Assignment
var assignments []*Assignment

for _, stmt := range d.Statements {
if assign, ok := stmt.(*Assignment); ok {
values = append(values, assign)
for _, statement := range d.Statements {
if assign, ok := statement.(*Assignment); ok {
assignments = append(assignments, assign)
}
}

for _, grp := range d.Groups {
for _, stmt := range grp.Statements {
if assign, ok := stmt.(*Assignment); ok {
values = append(values, assign)
for _, group := range d.Groups {
for _, statement := range group.Statements {
if assignment, ok := statement.(*Assignment); ok {
assignments = append(assignments, assignment)
}
}
}

return values
return assignments
}

func (d *Document) GetGroup(name string) *Group {
Expand Down

0 comments on commit 80b8f30

Please sign in to comment.