github.com/upcmd/up@v0.8.1-0.20230108151705-ad8b797bf04f/tests/functests/c0102.yml (about) 1 doc_meta: | 2 folder: cmd-func 3 title: delete in yml file 4 head: | 5 yml_delte cmd allow you to delete key from a yml file. 6 7 sections: 8 - title: How to use 9 content: | 10 * ymlfile: the yml filename 11 * refdir: optional directory of the ymlfile located, default to the global refdir from command line, or global configured 12 * path: path is the yq path 13 * reg: the var name to register to 14 * flags: 15 * localOnly: to indicate that the registered var is in local func var scope 16 * inpace: the delete operation applied directly to file, otherwise the change will be made to the registered var only 17 18 Note that inplace and reg/localOnly are mutual exclusive 19 20 - title: Demo 21 log: yes 22 23 related: 24 refs: 25 - title: yq and yq path reference 26 link: https://github.com/mikefarah/yq 27 28 29 notes: 30 goal: 31 - add feature to delete a node from yaml file 32 - inplace and reg/localOnly are mutual exclusive 33 - refdir is optional, if empty then default to global configured 34 35 vars: 36 mock_yml: | 37 tom: 38 sex: male 39 age: 23 40 jason: 41 sex: male 42 age: 35 43 emily: 44 sex: female 45 age: 32 46 47 tasks: 48 - 49 name: task 50 task: 51 - func: shell 52 do: 53 - 'echo "{{.mock_yml}}" > /tmp/mock_yml.yml' 54 55 - 56 func: cmd 57 desc: inplace modification 58 do: 59 - name: ymlDelete 60 cmd: 61 ymlfile: mock_yml.yml 62 refdir: /tmp 63 path: jason.sex 64 verbose: v 65 flags: 66 - inplace 67 68 69 - name: readFile 70 desc: check new file content 71 cmd: 72 filename: mock_yml.yml 73 dir: /tmp 74 reg: new_yml 75 76 - name: print 77 desc: show the modified yml content read from file 78 cmd: '{{.new_yml}}' 79 80 - 81 func: cmd 82 desc: modify in memory and register to cache 83 do: 84 - name: ymlDelete 85 cmd: 86 ymlfile: mock_yml.yml 87 refdir: /tmp 88 path: jason.sex 89 verbose: vvvv 90 reg: modified_yml 91 flags: [localOnly] 92 93 - name: print 94 desc: show the modified yml content registered 95 cmd: '{{.modified_yml}}' 96