subo icon indicating copy to clipboard operation
subo copied to clipboard

subo create runnable flag for directly exposing on Directive

Open flaki opened this issue 3 years ago • 3 comments

Currently subo create runnable doesn't touch the Directive at all.

In certain situations it might be useful to append the newly created runnable to the Directive and expose it as a handler straight away. This is a functionality that is being added as #134 as a separate command -- but it might be that it would make sense also as a flag on create runnable.

This flag, say subo create runnable X --handler would create the runnable X and append it to the directive as a handler /X. Alternatively if specified as ... --handler foo, that would set the handler to /foo instead.

The equivalent currently via shell is

# create the runnable
subo create runnable X
tee -a Directive.yaml << EOF
  - type: request
    method: GET
    resource: /X
    steps:
      - fn: X
EOF

flaki avatar Jan 20 '22 22:01 flaki

I want to work on this.

yashikajotwani12 avatar Apr 21 '22 12:04 yashikajotwani12

The task is to amend the existing subo create runnable command, so it accepts a flag.

The flag is --handler, it should have an optional argument, and it should NOT have a shorthand.

The expectations are:

1. subo create runnable doSomething

This works as expected, creates a directory named doSomething. This is how the current command works. This should not change.

2. subo create runnable doSomething --handler

Creates the directory and necessary files in the doSomething directory. On top of that, it ALSO modifies the root level Directive.yaml file by adding a new entry to the handlers array for a type request, method GET, resource /doSomething, ie the same as the runnable name with a / prepended.

3. subo create runnable doSomthing --handler /endpoint

Creates the directory and necessary files in the doSomething directory.

On top that, it also modifies the root level Directive.yaml file by adding a new entry to the handlers array for type: request, method: GET, and resource: /endpoint; the same as the argument to the --handler flag.

Not part of this issue

  • Don't need to add a way to customize method type
  • Don't need to add a way to customize the type (ie request or group)

Suggestions

One way this can be solved is to invoke the subo create handler command from within the running create runnable command and let that take care of manipulating the Directive.yaml file.

Another way to do it is to parse the existing yaml file into a struct, add the required handler to the struct, and then write that struct into a yaml file replacing the entire contents of it. There's code on how to do this in the create handler command.

javorszky avatar Apr 21 '22 14:04 javorszky

Cobra documentations:

https://cobra.dev/

https://github.com/spf13/cobra

javorszky avatar Apr 21 '22 14:04 javorszky