Giter Club home page Giter Club logo

Comments (11)

smyrman avatar smyrman commented on May 18, 2024 1

Done. Note that I might now be leaning towards adding args anyhow... Se #31 for why.

from task.

andreynering avatar andreynering commented on May 18, 2024

This is currently only partially supported.

You can specify globbing in sources and generates, but Task will rerun everything once any file change.

No way to do 1-to-1 file mapping yet.

from task.

smyrman avatar smyrman commented on May 18, 2024

In Makefiles, this feature is not only to avoid unnecessary work, as it also allows basic templating of tasks for use with different parameters.

E.g. if we where to produce a deb package for N binaries, it would be cool if there was a way to allow for templating / task reusability.

from task.

smyrman avatar smyrman commented on May 18, 2024

Could a syntax like this work?

template-task:
  args:
    - FILENAME
  cmds:
    - markdown {{.FILENAME}}.md > {{.FILENAME}}.html
  sources:
    - {{.FILENAME}}.md
  generates:
    - {{.FILENAME}}.html

The template task may only be used in another task. E.g. like this:

using-template:
  cmds:
    - ^template-task FILENAME=index

A more complex usage would want to call the template-task with either a list of input parameters, or maybe even somehow retrieve this list via a glob pattern!

from task.

smyrman avatar smyrman commented on May 18, 2024

I guess the glob pattern could be retrieved via a dynamic variable... FILENAMES=$ls *.md | sed 's/\.md$//g'. Of course, this might make it OS specific...

UPDATE: Maybe better to do this using a Go template variable filter. Eg. a replace method supporting basic regex.

from task.

smyrman avatar smyrman commented on May 18, 2024

Rather adding yet-another-keyword args, I guess we could also use the existing vars, the only difference being that vars might be set when running sub-tasks? And that tasks are cached according to the variable values as well as the task name?

from task.

andreynering avatar andreynering commented on May 18, 2024

@smyrman I liked the idea! Yes, I would use existing vars instead of args.

Could you please open another issue for task parameters?

from task.

andreynering avatar andreynering commented on May 18, 2024

@smyrman Thanks

from task.

smyrman avatar smyrman commented on May 18, 2024

That would work but it would recompile every Markdown file any time any file in sources/*.md updated. Instead what we want is to establish that 1:1 mapping, done this way:

public/%.html: sources/%.md
	markdown $< > $@

I guess this is now possible via task parameters.

build:
  deps:
    - task: tmpl/md2html:
      vars:
        NAME: index
    - task: tmpl/md2html:
      vars:
        NAME: about
    - task: tmpl/md2html:
      vars:
        NAME: blog

tmpl/md2html:
  cmds:
    - markdown sources/{{.NAME}}.md > public/{{.NAME}}.html
  sources:
    - sources/{{.NAME}}.md
  generates:
    - public/{{.NAME}}.html

For more compact syntax, use the YAML-supported inline JSON vars: {"NAME": "index"},

UPDATE: fix typo ( use task: not cmd: as prefix when calling tasks)

from task.

smyrman avatar smyrman commented on May 18, 2024

Anyway, maybe the ticket could be closed?

from task.

andreynering avatar andreynering commented on May 18, 2024

@smyrman OK, this is partly implemented. Not completetly, since it can't automatically infer sources globs to commands like Make, but I'll close in favor of #82

from task.

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.