Coder Social home page Coder Social logo

Pass bashly.yml through ERB about bashly HOT 8 CLOSED

n-rodriguez avatar n-rodriguez commented on September 23, 2024
Pass bashly.yml through ERB

from bashly.

Comments (8)

DannyBen avatar DannyBen commented on September 23, 2024 1

Released 1.0.7 with this feature.
Minimal docs here: https://bashly.dannyb.co/advanced/erb-in-config/

Thanks for the suggestion.

from bashly.

DannyBen avatar DannyBen commented on September 23, 2024

Good idea. Do you have a sample YAML use case?

from bashly.

DannyBen avatar DannyBen commented on September 23, 2024

The implementation is ready if you want to try it.
Let me know if it aligned with your use case.

from bashly.

n-rodriguez avatar n-rodriguez commented on September 23, 2024

use case:

commands:
  - name: completions
    help: |-
      Generate bash completions
      Usage: eval "\$(ansible completions)"

  - name: ansible
    help: Ansible related commands
    commands:
      - name: playbook
        help: Run Ansible playbook
        flags:
          - long: --playbook
            short: -p
            arg: playbook
            help: Playbook name
            required: true
            repeatable: false
            allowed:
              <%- Dir['playbooks/**/*.yml'].each do |f| -%>
                <%- _, dir, file = f.split('/') -%>
              - <%= "#{dir}_#{file}".gsub('_', '-').gsub('.yml', '') %>
              <%- end -%>

With a bit of Ruby code :

#!/usr/bin/env ruby

require 'erb'

yaml = ERB.new(File.read('vendor/ansible-cli/bashly.yml'), trim_mode: "-").result
puts yaml

it gives :

      - name: playbook
        help: Run Ansible playbook
        flags:
          - long: --playbook
            short: -p
            arg: playbook
            help: Playbook name
            required: true
            repeatable: false
            allowed:
              - install-apache
              - install-burp
              - install-dns
              - ...

And users can automagically autocomplete the --playbook flag :)

from bashly.

n-rodriguez avatar n-rodriguez commented on September 23, 2024

Let me know if it aligned with your use case.

it does! thank you! ❤️

from bashly.

DannyBen avatar DannyBen commented on September 23, 2024

Ok cool.

  1. Note that I did not use the trim mode '-' - I just used the default ERB settings:

def load_erb_file(path)
YAML.load ERB.new(File.read(path)).result
end

if there is any reason to load it differently in your opinion, let me know

  1. I will release during the weekend
  2. As I see you have some DevOps template manipulations to deal with - you might be interested in Kojo - I used it a lot to transform Kubernetes manifests into something more human friendly.
  3. You know you can run bashly validate --verbose to see the rendered YAML, yes?

from bashly.

n-rodriguez avatar n-rodriguez commented on September 23, 2024

As I see you have some DevOps template manipulations to deal with - you might be interested in Kojo - I used it a lot to transform Kubernetes manifests into something more human friendly.

Seems nice, thank you!

You know you can run bashly validate --verbose to see the rendered YAML, yes?

I didn't know, thank you!

from bashly.

n-rodriguez avatar n-rodriguez commented on September 23, 2024

As I see you have some DevOps template manipulations to deal with - you might be interested in Kojo - I used it a lot to transform Kubernetes manifests into something more human friendly.

Actually I did something (a bit) similar but in Crystal : https://github.com/jbox-web/envtpl.cr

from bashly.

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.