Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

No valid input for array properties #6

Open
nrw opened this Issue Sep 6, 2012 · 10 comments

Comments

Projects
None yet
2 participants

nrw commented Sep 6, 2012

When creating a resource via a commandful cli, there seems to be no valid input for setting array properties (and parent/child relationships).

For example:

Group = resourceful.define('group', function() {
  this.array('people');
});

// trying to set the value of 'people'
// via command line throws this error
{
  "schema": {
    "links": [], 
    "name": "Group", 
    "properties": {
      "id": {
        "required": false, 
        "type": "any"
      }, 
      "people": {
        "conditions": {}, 
        "messages": {}, 
        "type": "array"
      }
    }
  }, 
  "validate": {
    "errors": [
      {
        "actual": "string", 
        "attribute": "type", 
        "expected": "array", 
        "message": "must be of array type", 
        "property": "people"
      }
    ], 
    "valid": false
  }, 
  "value": {
    "id": "group_id", 
    "people": ""
  }
}
Contributor

Marak commented Sep 6, 2012

The Array type isn't supported yet in commandful

As for relationships, they are half implemented. It should be possible to use relational resources and set the foreign key via the prompt. What should be added is an additional prompt to create a new relational resource, versus having to manually set and get the ids through two commands.

Should be easy to add both, just haven't gotten around to it yet.

nrw commented Sep 6, 2012

Thanks for the quick response. I'll hold my breath waiting for the new features. :)

Contributor

Marak commented Sep 6, 2012

@nrw - What behavior are you trying to get out of the Array type?

Are you trying to store an array of strings, or are you trying to create a relationship between two resources and store an array of objects?

nrw commented Sep 6, 2012

In the example above, I'm trying to store an array of strings.

I'd certainly like to have an interface for adding children, too. You said relationships are partially implemented. Is this piece done? I'd love to see an example use.

Contributor

Marak commented Sep 6, 2012

@nrw - Understood. I'm working on both right now.

Trying to determine the best user-experience for the case of adding items to an Array.

I'm thinking, it should continually prompt for new values until the user types a special word like done or stop. Not sure of another way it could work that would make sense.

nrw commented Sep 6, 2012

In the interest of avoiding reserving a word, here's a thought:

If the user submits a blank value, prompt something to this effect:

(a)dd an empty string to this array? or are you (d)one entering values? [d]:

Is that a better idea?

Contributor

Marak commented Sep 6, 2012

Was my first thought. I dislike that because it increases the amount of reading and key-strokes by a factor of three.

The reserved word could be an empty value. I'll roll with this idea and see how it feels. If it doesn't work I might go back and do a menu option instead.

Thanks.

Contributor

Marak commented Sep 6, 2012

Created ticket in prompt for array type flatiron/prompt#54

nrw commented Sep 6, 2012

I'm glad to try whatever you come up with. :)

Some thoughts about the interface (i wrote these out for myself and they seemed worth sharing. i'm sure there is a better idea out there.)

No value + enter to stop (plus empty string mapping):

This one seems like the best option (to me). You map something like '' and/or "" to store an empty string. It's way easier to read on screen than other options and only prevents a really unusual value.

$ app group create
warn:    prompting user for data
info:    define new group
prompt: id:  group1
prompt: people: add item: sam
prompt: people: add item: ''
prompt: people: add item: <enter>
info: created group

enter twice to stop:

This way results in one less keystroke, but way more text on the screen.

$ app group create
warn:    prompting user for data
info:    define new group
prompt: id:  group1
prompt: people: add item: sam
prompt: people: add item: <enter>
prompt: people: (a)dd empty string? or be (d)one [d]: a <enter>
prompt: people: add item: <enter>
prompt: people: (a)dd empty string? or be (d)one [d]: <enter>
info: created group

done + enter to stop:

This way doesn't let you use the word done as an array value

$ app group create
warn:    prompting user for data
info:    define new group
prompt: id:  group1
prompt: people: add item: sam
prompt: people: add item: <enter>
prompt: people: add item: done
info: created group

No value + enter to stop:

This way doesn't let you set an empty string as an array value.

$ app group create
warn:    prompting user for data
info:    define new group
prompt: id:  group1
prompt: people: add item: sam
prompt: people: add item: <enter>
info: created group

Ask for add or done intention after each item:

The menu I'm picturing has a lot more key strokes. Do you have something else in mind?

$ app group create
warn:    prompting user for data
info:    define new group
prompt: id:  group1
prompt: people: add or done? [add]: <enter>
prompt: people: add item: sam
prompt: people: add or done? [add]: <enter>
prompt: people: add item: <enter>
prompt: people: add or done? [add]: done
info: created group
Contributor

Marak commented Sep 6, 2012

I've got a good start to adding both of these new features to commandful, but I'm now blocked on both by: flatiron/prompt#54 ( since foreign keys are stored in typed arrays )

Once we clear that issue up I'll pull in the new prompt and push my commandful changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment