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

Appending new variable declaration in a var(...) block #134

Open
rosroble opened this issue Aug 17, 2023 · 1 comment
Open

Appending new variable declaration in a var(...) block #134

rosroble opened this issue Aug 17, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@rosroble
Copy link

Hello!

I have a global var block as follows:

var (
	SystemSubsystem                   = "system"
	SystemLabelNames                  = []string{"hostname", "resource", "system_id"}
	SystemMemoryLabelNames            = []string{"hostname", "resource", "memory", "memory_id"}
// and so on
)

Let's say I want to insert a new variable SystemProcessorLabelNames after the SystemMemoryLabelNames

This doesn't work:

@@
@@
SystemMemoryLabelNames            = []string{"hostname", "resource", "memory", "memory_id"}
+SystemProcessorLabelNames         = []string{"hostname", "resource", "processor", "processor_id"}

And this doesn't work:

@@
@@
var (
...
SystemMemoryLabelNames            = []string{"hostname", "resource", "memory", "memory_id"}
+SystemProcessorLabelNames         = []string{"hostname", "resource", "processor", "processor_id"}
)

Although replacing works fine like that:

@@
@@
-[]string{"hostname", "resource", "memory", "memory_id"}
+[]string{"hostname", "resource", "processor", "processor_id"}

But I need to append a new line. Appending works fine inside functions, just like that:

@@
@@
a := 5
+b:=6

But inside var block it either fails or skips the file. Is this a bug or my mistake? Thanks.

@r-hang r-hang added the enhancement New feature or request label Aug 22, 2023
@lverma14
Copy link
Collaborator

lverma14 commented Aug 22, 2023

Hi, gopatch doesn't yet support elision in value declarations #6 .
But it should work against the format specified in the patch. Ref
The below patch should work & add the new line.

@@
@@
 var (
  SystemSubsystem        = "system"
  SystemLabelNames       = []string{"hostname", "resource", "system_id"}
  SystemMemoryLabelNames = []string{"hostname", "resource", "memory", "memory_id"}
+ SystemProcessorLabelNames = []string{"hostname", "resource", "processor", "processor_id"}
 )

Thank you for reporting this! We plan to fix this in the future versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

3 participants