Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run/push: support "subargs" for forwarding to remote process. Fixes gh-732 #806

Merged
merged 1 commit into from
Jul 22, 2016

Conversation

rwaldron
Copy link
Contributor

Uses the "subarg" syntax:

t2 run index.js [foo bar baz -a 1 -b 2 --named --key=value]

Will result in process.argv on the deployed program:

[ '/usr/bin/node',
  '/tmp/remote-script/index.js',
  'foo',
  'bar',
  'baz',
  '-a',
  '1',
  '-b',
  '2',
  '--named',
  '--key=value' ]

Smoke Test

(pull this branch locally)

  1. Create a new project:
    mkdir t2-732 && cd t2-732 && t2 init; npm install minimist --save

  2. Open the index.js just now and replace the contents with:

    var argv = require('minimist')(process.argv.slice(2));
    
    console.log(argv);
  3. Run t2 run index.js [foo bar baz -a 1 -b 2 --named --key=value]

Deployment should look something like this:

$ t2 run index.js [foo bar baz -a 1 -b 2 --named --key=value]
INFO Looking for your Tessel...
INFO Connected to ash.
INFO Building project.
INFO Writing project to RAM on ash (9.728 kB)...
INFO Deployed.
INFO Running index.js...
{ _: [ 'foo', 'bar', 'baz' ],
  a: 1,
  b: 2,
  named: true,
  key: 'value' }

Signed-off-by: Rick Waldron waldron.rick@gmail.com

args[i] = arg.slice(0, arg.length - 1);
eIndexOfSA = i;
}
}
Copy link
Contributor Author

@rwaldron rwaldron Jul 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EDIT: I deleted the line note because I'm adding the content as a comment in the source

@rwaldron
Copy link
Contributor Author

@ebruchez wdyt?

@HipsterBrown review?

@@ -284,7 +284,8 @@ exports['Tessel.prototype.deploy'] = {
test.expect(12);
deployTestCode(this.tessel, {
push: true,
single: false
single: false,
subargs: [],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should pass without the subargs property as well, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because this test runs code that exists at a point in which all default properties are resolved, so the subargs property will always be present, either empty or with contents

@HipsterBrown
Copy link
Contributor

HipsterBrown commented Jul 20, 2016

Code looks good to me. I can't do a smoke test tonight. I can do a smoke test tonight. Typo before.

A few questions:

  • Would you suggest using subargs to pass through things like API tokens instead of environment variables?
  • Could we also pass through environment variables in a similar way?

@HipsterBrown
Copy link
Contributor

Smoke test results:

Nicks-MacBook-Pro:tessel-test hipsterbrown$ mkdir t2-732 && cd t2-732 && t2 init; npm install minimist --save
INFO Initializing new Tessel project for JavaScript...
INFO Created package.json.
INFO Created .tesselinclude.
INFO Wrote "Hello World" to index.js
minimist@1.2.0 node_modules/minimist
Nicks-MacBook-Pro:t2-732 hipsterbrown$ vim index.js
Nicks-MacBook-Pro:t2-732 hipsterbrown$ t2 run index.js [foo bar baz -a 1 -b 2 --named --key=value]
INFO Looking for your Tessel...
INFO Which Tessel do want to use?   LAN tessel-router
INFO Connected to tessel-router.
INFO Building project.
INFO Writing project to RAM on tessel-router (9.728 kB)...
INFO Deployed.
INFO Running index.js...
{ _: [ 'foo', 'bar', 'baz' ],
  a: 1,
  b: 2,
  named: true,
  key: 'value' }
Nicks-MacBook-Pro:t2-732 hipsterbrown$

Looks like a successful test! 👍

@rwaldron
Copy link
Contributor Author

Could we also pass through environment variables in a similar way?

TBH, I'm not sure and this is an interesting question. I will do some tests and report back

@rwaldron
Copy link
Contributor Author

Could we also pass through environment variables in a similar way?

I've spent some time with this question and have determined that this patch is not an appropriate mechanism to shoe-horn other features into. I'm going to stop at "just subargs" here.

@HipsterBrown
Copy link
Contributor

@rwaldron Sounds good. I appreciate you taking the time to investigate that concept. LGTM 👍

…esselgh-732

Uses the "subarg" syntax:

t2 run index.js [foo bar baz -a 1 -b 2 --named --key=value]

Will result in process.argv on the deployed program:

[ '/usr/bin/node',
  '/tmp/remote-script/index.js',
  'foo',
  'bar',
  'baz',
  '-a',
  '1',
  '-b',
  '2',
  '--named',
  '--key=value' ]

Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants