Git Product home page Git Product logo

Comments (1)

georgehansper avatar georgehansper commented on August 26, 2024 1

In general, Augeas lenses create files which are syntactically correct for a given syntax (such as Json), they do not necessarily make them "pretty".

Part of the problem is that for many languages such as JSON, spaces are not significant. So when a new entry is created, the amount of space that can or should be inserted becomes arbitrary.

In this case, it may be possible to update the lens to produce a more readable output, though I expect the indentation would remain messy.

I find it odd that appending another entry after "groups" inserts the new entry directly between previous one and the }

> augtool --noload  --noautoload 
augtool> set /augeas/load/Json/lens Json.lns
augtool> set /augeas/load/Json/incl /tmp/policy.json
augtool> load-file /tmp/policy.json
augtool> set /files/tmp/policy.json/dict/entry[last()+1] 'extra1'
augtool> set /files/tmp/policy.json/dict/entry[.='extra1']/string 'hello'
augtool> set /files/tmp/policy.json/dict/entry[last()+1] 'extra2'
augtool> set /files/tmp/policy.json/dict/entry[.='extra2']/string 'world'
augtool> preview /files/tmp/policy.json/
{
    "context_is_admin": "role:admin or role:load-balancer_admin",
    "admin_or_owner": "is_admin:True or project_id:%(project_id)s",

    "load-balancer:read": "rule:admin_or_owner",
    "load-balancer:read-global": "is_admin:True",
    "load-balancer:write": "rule:admin_or_owner",
    "load-balancer:read-quota": "rule:admin_or_owner",
    "load-balancer:read-quota-global": "is_admin:True",
    "load-balancer:write-quota": "is_admin:True"
,
"extra1":"hello","extra2":"world"}augtool> 

There is definitely room for improvement here

from augeas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.