Giter Club home page Giter Club logo

Comments (5)

simon-spinner avatar simon-spinner commented on September 13, 2024

Have you tried to use string concatenation in option 1?

--ssc-network-info '[{"port": 444, "ipaddr-type": "static", "vlan-id": '$vlan_id', "static-ip-info": {"type": "ipv4", "ip-address": "'$ip_address'"}}]'

You need to put the shell variables in single quotation marks (basically end and start the string again). But at least bash typically concatenates everything and passes it as a single string to the program

from zhmccli.

simon-spinner avatar simon-spinner commented on September 13, 2024

Another observation: Option 2 looks very similar to the single line syntax of YAML. The most obvious difference is that you need commas between fields of an object and use : instead of =

from zhmccli.

andy-maier avatar andy-maier commented on September 13, 2024

Option 3: Single line YAML (aka "Flow Style")

The YAML spec calls this Flow Collection Styles.

Some sources claim that quotes around property names and string values would be needed, but that does not seem to be the case. Example: https://yaml-online-parser.appspot.com/?yaml=prop%3A+%7Bresult%3A+42%2C+name%3A+alice%7D%0A&type=json
Also the YAML spec confirms that no quotes are needed, see Example 7.15: https://yaml.org/spec/1.2.2/#rule-ns-s-flow-map-entries

Note that the flow collection style YAML is a superset of JSON, so double quotes around property names and string values can also be used.

Example for "ssc-network-info":

--ssc-network-info "[{port: 444, ipaddr-type: static, vlan-id: 53, static-ip-info: {type: ipv4, ip-address: '10.11.12.13'}}]"

Example for "ssc-network-info" when using shell/env variables:

--ssc-network-info "[{port: 444, ipaddr-type: static, vlan-id: $vlan_id, static-ip-info: {type: ipv4, ip-address: '$ip_address'}}]"

Examples with a (fantasy) escaped string value:

--properties '{description: ab\ncd}'
--properties "{description: ab\\ncd}"

I must say, I like option 3 the best.

We probably need to write a help topic with a short explanation of the syntax, since the YAML spec is hard to read for occasional users.

More understandable descriptions of flow style that we could refrence:

Probably not so good:

from zhmccli.

andy-maier avatar andy-maier commented on September 13, 2024

I have implemented option 3 in PR #537 - if we agree on that PR, I consider the decision made for using option 3.

from zhmccli.

andy-maier avatar andy-maier commented on September 13, 2024

We agreed on PR #537, so we will continue using option 3 in the future.
This issue is now complete.

from zhmccli.

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.