Code Monkey home page Code Monkey logo

Comments (5)

drewmacinnis avatar drewmacinnis commented on August 15, 2024

Yeah, a -f would be handy.

from gomplate.

hairyhenderson avatar hairyhenderson commented on August 15, 2024

Something that might be a bit simpler to implement, and would probably flow better with the rest of the built-in functions is:

Hello {{ (jsonfile "data.json").name.first }}
$ gomplate -d data.json < in.txt
Hello Joe!

from gomplate.

hairyhenderson avatar hairyhenderson commented on August 15, 2024

...although if I'm taking a path or filename as the argument to jsonfile, then I don't need to pass it on the commandline...

Conversely, forcing a file to be named a specific way may not be a good plan either. Maybe something like:

Hello {{ (jsonfile "data").name.first }}
$ gomplate -d data.json < in.txt
Hello Joe!

Where "data" is resolved because the file is named data.json. I could support mappings with = like:

$ gomplate -d data=myotherfilename.json < in.txt
Hello Joe!

It'd be interesting to also support other data sources from URLs, so to treat the -d argument like: alias=URL, or:

$ gomplate -d data=https://some.url/where/i/can/find/data.json < in.txt
Hello Joe!

This implies a few things:

  1. jsonfile is a bad name - it should be something more generic like datasource
  2. in the absence of =, the argument is assumed to be a file in the cwd, and the alias is set to the file name (sans extension)
  3. paths (i.e. anything with a directory name in it, not just the filename) and URLs would require the alias

from gomplate.

drmdrew avatar drmdrew commented on August 15, 2024

I like the "data source alias" idea. Perhaps always use uri style? Like file:// https://?

from gomplate.

hairyhenderson avatar hairyhenderson commented on August 15, 2024

yeah - well data.json is technically a valid relative URL, so if we always use the cwd as the base file:// url, there shouldn't be any special-casing needed.

I was also thinking I could support lots of different formats this way (eventually!) like yaml or toml or even XML, detecting by Content-Type with a fallback to file extension...

from gomplate.

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.