Skip to content

Generated flag manifest file should end with final newline #194

@sahidvelji

Description

@sahidvelji

This might be a bit of a nit, but text files should end with a newline character.

> openfeature manifest add enableMagicButton --type boolean --default-value false --description "Activates a special button that enhances user interaction with magical, intuitive functionalities."
 SUCCESS  Flag 'enableMagicButton' added successfully to flags.json
❯ od -c flags.json
0000000    {  \n           "   $   s   c   h   e   m   a   "   :       "
0000020    h   t   t   p   s   :   /   /   r   a   w   .   g   i   t   h
0000040    u   b   u   s   e   r   c   o   n   t   e   n   t   .   c   o
0000060    m   /   o   p   e   n   -   f   e   a   t   u   r   e   /   c
0000100    l   i   /   r   e   f   s   /   h   e   a   d   s   /   m   a
0000120    i   n   /   s   c   h   e   m   a   /   v   0   /   f   l   a
0000140    g   -   m   a   n   i   f   e   s   t   .   j   s   o   n   "
0000160    ,  \n           "   f   l   a   g   s   "   :       {  \n
0000200                "   e   n   a   b   l   e   M   a   g   i   c   B
0000220    u   t   t   o   n   "   :       {  \n
0000240    "   d   e   f   a   u   l   t   V   a   l   u   e   "   :
0000260    f   a   l   s   e   ,  \n                           "   d   e
0000300    s   c   r   i   p   t   i   o   n   "   :       "   A   c   t
0000320    i   v   a   t   e   s       a       s   p   e   c   i   a   l
0000340        b   u   t   t   o   n       t   h   a   t       e   n   h
0000360    a   n   c   e   s       u   s   e   r       i   n   t   e   r
0000400    a   c   t   i   o   n       w   i   t   h       m   a   g   i
0000420    c   a   l   ,       i   n   t   u   i   t   i   v   e       f
0000440    u   n   c   t   i   o   n   a   l   i   t   i   e   s   .   "
0000460    ,  \n                           "   f   l   a   g   T   y   p
0000500    e   "   :       "   b   o   o   l   e   a   n   "  \n
0000520            }  \n           }  \n   }
0000531

The very last byte is a } instead of \n.

The fix should be very simple. Just append the byte '\n' before writing the manifest to a file.

I believe it should be done here:

// writeManifest marshals and writes a manifest to the given path atomically
func writeManifest(path string, manifest *initManifest) error {
formattedManifest, err := json.MarshalIndent(manifest, "", " ")
if err != nil {
return err
}

	formattedManifest = append(formattedManifest, '\n')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions