Code Monkey home page Code Monkey logo

bash-yaml's People

Contributors

adriandc avatar brian-egan avatar daphipz avatar f-michaut avatar jasperes avatar kriansa avatar lumenpink avatar tinder-jlee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bash-yaml's Issues

Option to add a prefix to all variables parsed

Description

I have a use case where sometimes I do not want to overwrite already existing variables of the same name. So ideally, I want to have a separate namespace for all the yaml data.
Would it be possible to add an optional prefix to all variables/structs returned? So that in the lower example, the variable would be called e.g. configxy.myvar instead of myvar?

Yaml file to test

myvar: test
myarray:

  • 1
  • 2

Operation Sistem

[] Linux

Bash version

4.4.12(1)-release

list support incomplete

List didn't seems to works as expected.

I used test/tesh.sh and complex_test_simple_obj_a_list is empty (created by create_variables).
But parse_yaml report element members

Doesn't parse text with dollar signs

Description

Thanks for this great function! I'm new to Bash so am not in a place to tweak the code. I was using this to import yaml text that unfortunately includes a $. This is clearly an issue for bash but I was hoping there was an adjustment to add $ or something to the regex to allow this text to come in as a variable. For example:

settings:
  user:  'myname'
  pwd:  'pa$$word$20' # not real password of course

If I run create_variables config.yml then echo $settings_pwd it results in 'pa22336word0'.

Yaml file to test

default:
  driver: 'driver_name' 
  server: 'R$word$10'
  dsn: 'abcd'
  uid: 'GRP19$name!01'
  pwd: 'pa$$word$20'  
  port: 1234
  database: 'db.name'

Operation System

[] Linux
[] OSX
[] BSD
[X] Windows 10

Bash version

GNU bash, version 4.4.23(1)-release (x86_64-pc-msys)

Iterate over result

env:
  dev:
    enable: true
    host: 127.0.0.1
    port: 7090
  pro:
    enable: false
    host: 192.168.1.126
    port: 1090    

Parsing Sequence of Mappings

Description

When parsing a sequence of mappings, the parser is unable to create variables from keys that are not indented at the same level as the first key.

sample:
  - item-one:
    name: item-one-name
    
  - item-two:
      name: item-one-name

While both item-one and item-two are considered to be valid yaml, this parser is only able to parse the first variation, and ${sample__name[1]} is empty.

echo "Item 1: ${sample__name[0]}"
Item 1: item-one-name

echo "Item 2: ${sample__name[1]}"
Item 2:

Operation System

  • Linux
  • OSX
  • BSD

Bash version

GNU bash, version 3.2.57(1)-release

not getting array

Description

There should be two host in spec__host but instead, there is 1, I'm puttng my bash file with the output which is wrong in the case of db

Yaml file to test

backupname: mybakcup
spec:
 -  host: localhost
    port: 25060
    awsid: AAA
    awskey: BBB
    dbs:
    - dbname: testdb1
      username: db1_username
      passowrd: db1_password
    - dbname: testdb2
      username: db2_username
      passowrd: db2_password
 -  host: localhost2
    port: 2222
    awsid: ZZZZ
    awskey: XXXX
    dbs:
    - dbname: testdb1
      username: db1_username
      passowrd: db1_password
    - dbname: testdb2
      username: db2_username
      passowrd: db2_password

Bash file

 echo "No of Hosts found ${#spec__host[@]}"
  for i in ${!spec__host[@]}; do
      echo ${spec__host[$i]} ${spec__port[$i]} ${spec__awsid[$i]}
      for i in ${!spec___dbname[@]}; do
          echo "No of DB found ${#spec___dbname[@]}"
          echo ${spec___dbname[$i]} ${spec___username[$i]} ${spec___passowrd[$i]}
      done
  done

output

No of Hosts found 1
localhost2 2222 ZZZZ
No of DB found 4
testdb1 db1_username db1_password
testdb2 db2_username db2_password
testdb1 db1_username db1_password
testdb2 db2_username db2_password 

Operation Sistem

[x] Linux
[] OSX
[] BSD

Bash version

GNU bash, version 5.1.0(1)-release (x86_64-pc-linux-gnu)

osx bug fix: awk: calling undefined function gensub

# mac bug fix
AWK_COMMAND=`[ "$(uname)" == "Darwin" ] && echo gawk || echo awk`
program_exists() {
    local ret='0'
    command -v $1 >/dev/null 2>&1 || { local ret='1'; }
    if [ "$ret" -ne 0 ]; then
        echo 0
    fi
    echo 1
}
if [ "$(uname)" == "Darwin" ] && [ $(program_exists gawk) -eq 0 ]; then
    echo "Command not found: gawk"
    echo "    Use Homebrew and then just run: brew install gawk"
    exit 1;
fi
...
${AWK_COMMAND} -F"$fs" '{
...

get sub vars from array

Description

Im use some array of packages in yml, and when im try to get in loop the sub vars of the array var im get only once the last one in first loop.

Yaml file to test

packages:
  - name: name of package
    package: type
      ver: 1.0
      zip: http://com.zip
  - name: name of package2
    package: type2
      ver: 1.2
      zip: http://com2.zip

Operation Sistem

  • Linux

Bash version

4.4.20(1)-release

Test on FreeBSD return error!

Here are the --debug output..

bash test.sh --debug
person_name=("Jonathan")
person_age=("99")
person_email=("[email protected]")
persons__name+=("'Maria'")
persons__age+=("'88'")
persons__email+=("'[email protected]'")
persons__name+=(""João"")
persons__age+=(""77"")
persons__email+=(""[email protected]"")
complex_test_simple_obj_attr=(""value"")
complex_test_simple_obj_other_attr=("other "value"")
complex_test_simple_obj_chaos_list+=("n attr: value1")
complex_test_simple_obj_chaos_list__otherv+=("value1v")
complex_test_simple_obj_chaos_list__attr+=("value2")
complex_test_simple_obj_chaos_list__otherv+=(""value2v"")
complex_test_simple_obj_a_list+=("0")
complex_test_simple_obj_a_list+=("1")
complex_test_simple_obj_a_list+=("2")
complex_test_simple_obj_a_list+=("3")
complex_test_simple_obj_a_list+=("4")
complex_test_simple_obj_a_list+=("5")
complex_test_simple_obj_a_list+=("6")
complex_test_simple_obj_a_list+=("7")
complex_test_simple_obj_a_list+=("8")
complex_test_simple_obj_a_list+=("9")
more_tests_double_dashes=("--ok")
more_tests_dot_start=(".dot")
more_tests_some_propertie=("some-propertie ok!")
more_tests_domain_com=("domain.com ok!")
more_tests_inline_comment=("something")
more_tests_comment_with_hash=("an#hash")
more_tests_hash=("a#hash")
more_tests_single_quotes_hash1=("'a#hash'")
more_tests_single_quotes_hash2=("'a #hash'")
more_tests_single_quotes_hash3=("'#hi'")
more_tests_single_quotes_comment_in_string=("'a string...'")
more_tests_double_quotes_hash1=(""a#hash"")
more_tests_double_quotes_hash2=(""a #hash"")
more_tests_double_quotes_hash3=(""#hi"")
more_tests_double_quotes_comment_in_string=(""a string..."")
more_tests_a_multi_dash_property=("result-is=OK")
more_tests_a_multi_dot_property=("result.is=OK")
more_tests_a_property_that_has_quite_a_number_of_dashes=("result-is=OK")
more_tests_a_property_that_has_dashes_and_dots=("result-is.absolutely=fine.and-perfect")

Error on execute tests!

Last character 's' is missing

test_yamls:
  -
    key: app
    file: test-app.yaml
    description: Front end code
  -
    key: tasks
    file: test-long-tasks.yaml
    description: Backend end code

After being parsed
test_yamls__key[1] holds the value task instead of tasks

Doesn't allow to have double quotes in comments

Description

If there is a double quote in comment then whole string is included as the value

Yaml file to test

--
name: test
process:
  name: 4K #this "comment" will be included in variable

Operation Sistem

  • Linux
  • OSX
  • BSD

Bash version

bash 3.2

Request : Extend to Get Specific Property value from YAML file

Description

I would like to request a new feature or extension where a getValue function to get the value of a Property provided the Property name and YAML file.

Property can be something like Domains_Domain[1]_Name - 'underscore' separated fields' names.

Refer to the YAML file and example of what I am trying to achieve at https://stackoverflow.com/questions/70101607/shell-function-to-get-value-of-a-property-from-yaml-file. I mentioned the same below as well.

DomainName=getValue Domains_Domain[1]_Name /path/my_yaml.yml

AppSpaceName=getValue Domains_Domain[$DomainName]_AppSpaces_AppSpace[1]_Name /path/my_yaml.yml

AppNodeName=getValue Domains_Domain[$DomainName]_AppSpaces_AppSpace[$AppSpaceName]_AppNodes_AppNode[1]_Name /path/my_yaml.yml

AppName=getValue Domains_Domain[$DomainName]_AppSpaces_AppSpace[$AppSpaceName]_AppNodes_AppNode[$AppNodeName]_Applications_Application[1]_Name /path/my_yaml.yml

AppVersion=getValue Domains_Domain[$DomainName]_AppSpaces_AppSpace[$AppSpaceName]_AppNodes_AppNode[$AppNodeName]_Applications_Application[$AppName]_Version /path/my_yaml.yml

Yaml file to test

---
Action: start
Version: 642
Domains:
  Domain:
    Name: SanityTest
    AppSpaces:
      AppSpace:
        Name: SanityAppSpace
        AppNodes:
          AppNode:
            Name: SanityAppnode
            Applications:
              Application:
                Name: InstagramTest.application
                Version: "1.0"
          AppNode:
            Name: SanityAppnode_1
            Applications:
              Application:
                Name: InstagramTest.application
                Version: "1.0"

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.