Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comment block disappears #505

Closed
miguelmota opened this issue Jul 29, 2020 · 6 comments
Closed

Comment block disappears #505

miguelmota opened this issue Jul 29, 2020 · 6 comments
Labels
Milestone

Comments

@miguelmota
Copy link

miguelmota commented Jul 29, 2020

Describe the bug
Inplace writing is deleting comment blocks

version of yq: 3.3.2
operating system: Linux archlinux 5.4.36-1-lts #1 SMP Wed, 29 Apr 2020 16:23:03 +0000 x86_64 GNU/Linux

Input Yaml
Concise yaml document(s) (as simple as possible to show the bug)
data1.yml:

(Removed by Mike - too long)

@miguelmota miguelmota added the bug label Jul 29, 2020
@mikefarah
Copy link
Owner

Can you please provide a small example of yaml - I can't make sense of this

@miguelmota
Copy link
Author

~/.config/alacritty/alacritty.yml

background_opacity: 0.6

key_bindings:
  # (Windows/Linux only)
  #- { key: V,        mods: Control|Shift, action: Paste            }
  #- { key: C,        mods: Control|Shift, action: Copy             }
  #- { key: Insert,   mods: Shift,         action: PasteSelection   }
  #- { key: Key0,     mods: Control,       action: ResetFontSize    }
  #- { key: Equals,   mods: Control,       action: IncreaseFontSize }
  #- { key: Add,      mods: Control,       action: IncreaseFontSize }
  #- { key: Subtract, mods: Control,       action: DecreaseFontSize }
  #- { key: Minus,    mods: Control,       action: DecreaseFontSize }
  #- { key: Return,   mods: Alt,           action: ToggleFullscreen }

  # (macOS only)
  #- { key: Key0,   mods: Command,         action: ResetFontSize    }
  #- { key: Equals, mods: Command,         action: IncreaseFontSize }
  #- { key: Add,    mods: Command,         action: IncreaseFontSize }
  #- { key: Minus,  mods: Command,         action: DecreaseFontSize }
  #- { key: K,      mods: Command,         action: ClearHistory     }
  #- { key: K,      mods: Command,         chars: "\x0c"            }
  #- { key: V,      mods: Command,         action: Paste            }
  #- { key: C,      mods: Command,         action: Copy             }
  #- { key: H,      mods: Command,         action: Hide             }
  #- { key: Q,      mods: Command,         action: Quit             }
  #- { key: W,      mods: Command,         action: Quit             }
  #- { key: F,      mods: Command|Control, action: ToggleFullscreen }

  - { key: Paste,                   action: Paste                            }
  - { key: Copy,                    action: Copy                             }
  - { key: L,        mods: Control, action: ClearLogNotice                   }
  - { key: L,        mods: Control, chars: "\x0c"                            }

Command to run:

yq w -i ~/.config/alacritty/alacritty.yml background_opacity 1

Expected: only modify background_opacity property.

Actual: It deleted comments unexpectedly:

background_opacity: 1
key_bindings:
  # (macOS only)
  #- { key: Key0,   mods: Command,         action: ResetFontSize    }
  #- { key: Equals, mods: Command,         action: IncreaseFontSize }
  #- { key: Add,    mods: Command,         action: IncreaseFontSize }
  #- { key: Minus,  mods: Command,         action: DecreaseFontSize }
  #- { key: K,      mods: Command,         action: ClearHistory     }
  #- { key: K,      mods: Command,         chars: "\x0c"            }
  #- { key: V,      mods: Command,         action: Paste            }
  #- { key: C,      mods: Command,         action: Copy             }
  #- { key: H,      mods: Command,         action: Hide             }
  #- { key: Q,      mods: Command,         action: Quit             }
  #- { key: W,      mods: Command,         action: Quit             }
  #- { key: F,      mods: Command|Control, action: ToggleFullscreen }
  - {key: Paste, action: Paste}
  - {key: Copy, action: Copy}
  - {key: L, mods: Control, action: ClearLogNotice}
  - {key: L, mods: Control, chars: "\f"}

@mikefarah
Copy link
Owner

Played around with this, looks likes its an issue with the underlying yaml parser:

go-yaml/yaml#686

@mikefarah mikefarah changed the title Writing inplace deletes comments Comment block disappears Jan 2, 2021
@mikefarah
Copy link
Owner

Note - as a (hacky) workaround if you remove or replace the empty line before key_binding, or the the empty line before the macOS comment - it seems to work. You could replace the empty line with an empty comment instead.

@miguelmota
Copy link
Author

@mikefarah thanks for the tip, removing empty lines prevented them from being removed

@mikefarah mikefarah added this to the 4.3.0 milestone Jan 8, 2021
@mikefarah
Copy link
Owner

Fixed in 4.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants