Skip to content

Task DSL for arg and positional_arg should warn about naming collisions #4

@robacarp

Description

@robacarp

This will put you in a world of confusion:

class MyTask < LuckyCli::Task
  arg :summary, "", optional: true
  positional_arg :name, ""

  def call(io : IO = STDOUT)
    # do stuff
  end
end

Macro-generated args can easily conflict with the in-use internal namespace in the task infrastructure. When you run lucky -h with that task in your tasks directory, you'll get an opaque error because calling .name on the class isn't doing what lucky_cli thought it would do. You'll get:

Unhandled exception: name is required, but no value was passed. (Exception)

I wonder if it makes sense to:

  • namespace the LuckyCli::Task infrastructure, for example instead of a summary method being generated from the summary macro, maybe it generates a _task_summary method.
  • encapsulate the declared arguments within an Args object of some sort. Within a task, a arg :summary would be accessed via args.summary instead of just summary.
  • simply warn the developer that they're about to shoot themselves in the foot by declaring an arg with a name of: name, summary, help_message, call, etc

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions