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

Add verbose option #7

Merged
merged 6 commits into from
May 1, 2017
Merged

Conversation

MarkTiedemann
Copy link
Contributor

My first pull request. :)

@MarkTiedemann
Copy link
Contributor Author

CI failed for nodejs_version=0.12 with the following output:

const debug = require('debug')('xo');
^^^^^
SyntaxError: Use of const in strict mode.

Should support for Node v0.12 get dropped or should the xo devDependency be downgraded?

@sindresorhus
Copy link
Owner

Should support for Node v0.12 get dropped or should the xo devDependency be downgraded?

I will do it after this PR. Just ignore Node.js 0.12 failures for now.

index.js Outdated
args.push('/apps');
}

if (Array.isArray(opts.filter)) {
Copy link
Owner

Choose a reason for hiding this comment

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

I prefer to keep it Array only. I don't like mixing types with little benefit.

readme.md Outdated

Type: `boolean`

Return verbose results (default: `false`).
Copy link
Owner

Choose a reason for hiding this comment

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

readme.md Outdated
status: 'Running',
username: 'SINDRESORHU3930\\sindre'
cpuTime: 0, // seconds
windowTitle: 'Task Host Window'
Copy link
Owner

Choose a reason for hiding this comment

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

I think it's useful for people to see the properties like this with values, so maybe add another example in the verbose option section and show these.

- Make test cases check all properties
- Revert making `memUsage` a `verbose` property (which it is not)
- Revert making `filter` option accept strings
- Add example to `verbose` option documentation
- Change formatting of default values in documentation
@MarkTiedemann
Copy link
Contributor Author

I have made the changes you requested and even fixed a bug in my code. :)

  • Make test cases check all properties
  • Revert making memUsage a verbose property (which it is not)
  • Revert making filter option accept strings
  • Add example to verbose option documentation
  • Change formatting of default values in documentation

@MarkTiedemann
Copy link
Contributor Author

Just noticed CI failed, and for good reason:

  • It seems like windowTitle won't be set in the CI env
  • The apps version returns different rows:
    • Specifically, it does not have sessionName and sessionNumber, but instead it has packageName
    • In verbose mode, it has both sessionName and sessionNumber as well as packageName

Gonna update the PR as soon as possible. :)

@MarkTiedemann
Copy link
Contributor Author

Earlier CI failed on Node 0.12 with linting errors, now it failed on Node 4, too.

@sindresorhus
Copy link
Owner

@MarkTiedemann What's the status of this PR? :)

@MarkTiedemann
Copy link
Contributor Author

Well, I (almost) forgot about the PR. ;)

But thanks to your question, last night I spent 2-3 hours revisiting, upgrading, re-testing, fixing, and completely refactoring the old code. :)

Not 100% happy with the results yet, and some documentation is still missing, but I'm probably gonna push the results in the next few days.

PS: Last time I worked on this PR a couple of weeks ago, I created a streaming version of this module: tasklist-stream. I think once this PR is done, we could perhaps merge both in some way (they do "share" a lot of code already ...).

This commit includes the following changes:

 - Update Node versions in appveyor.yml
 - Update dependencies
 - Use const instead of var
 - Use () => {} instead of function() {}
 - Remove Promise ponyfill
 - Remove 'N/A' check due to failure on non-English systems
 - Make the tests cases cover all returned tasks
@MarkTiedemann
Copy link
Contributor Author

@sindresorhus Here's my refactoring:

  • Update Node versions in appveyor.yml
  • Update dependencies
  • Use const instead of var
  • Use () => {} instead of function() {}
  • Remove Promise ponyfill
  • Remove 'N/A' check due to failure on non-English systems
  • Make the tests cases cover all returned tasks

Hope you like it. :)

Copy link
Owner

@sindresorhus sindresorhus left a comment

Choose a reason for hiding this comment

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

Looks really good. Just some minor nitpick.

test.js Outdated
t.is(typeof d.pid, 'number');
t.is(typeof d.memUsage, 'number');
});
const makeTest = (options, t) => {
Copy link
Owner

Choose a reason for hiding this comment

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

Can you use a test macro instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Been using ava since .9, I totally missed that you support test macros now. Thanks for the advice!

test.js Outdated
const makeTest = (options, t) => {
return tasklist(options).then(tasks => {
t.true(tasks.length > 0);
tasks.forEach(task => {
Copy link
Owner

Choose a reason for hiding this comment

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

Use a for-of loop.

test.js Outdated
import test from 'ava';
import fn from './';
const test = require('ava');
const tasklist = require('./');
Copy link
Owner

Choose a reason for hiding this comment

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

Don't change this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't like the inconsistency of having require statements in the index file and import statements in the test file. But I guess your plan is to change to import statements everywhere in the long run, so yeah, gladly changing it back. :)

package.json Outdated
"ava": "*",
"xo": "*"
"ava": "^0.19.1",
"xo": "^0.18.1"
Copy link
Owner

Choose a reason for hiding this comment

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

Don't change this.

package.json Outdated
},
"scripts": {
"test": "xo && ava"
"test": "xo --fix && ava --verbose"
Copy link
Owner

Choose a reason for hiding this comment

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

Don't change this.

package.json Outdated
@@ -10,10 +10,10 @@
"url": "sindresorhus.com"
},
"engines": {
"node": ">=0.10.0"
"node": ">=4.0.0"
Copy link
Owner

Choose a reason for hiding this comment

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

"node": ">=4"

test.js Outdated
t.is(typeof d.memUsage, 'number');
});
const makeTest = (options, t) => {
return tasklist(options).then(tasks => {
Copy link
Owner

Choose a reason for hiding this comment

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

Use async/await

index.js Outdated
args.push('/fi', el);
});
if (Array.isArray(options.filter)) {
options.filter.forEach(fi => args.push('/fi', fi));
Copy link
Owner

Choose a reason for hiding this comment

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

Use for-of loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was no for-loop before. I'm gladly changing it, but may I ask why?

Copy link
Owner

Choose a reason for hiding this comment

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

It's faster. I'm trying to use it over forEach whenever possible. So for consistency too. And I don't like inline arrow functions for things that doesn't return anything. Makes the code harder to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I understand that. Thanks for explaining!

PS: I have fixed the requested changes. :)

index.js Outdated
if (process.platform !== 'win32') {
return Promise.reject(new Error('Windows only'));
}

opts = opts || {};
const options = opts || {};
Copy link
Owner

Choose a reason for hiding this comment

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

Don't change this. I have it like this so it will be super easy to change to default parameters when I can target Node.js 6.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't think about that. Thanks for explaining. :)

@sindresorhus sindresorhus changed the title Add verbose option, add apps option, and update filter option Add verbose option May 1, 2017
@sindresorhus sindresorhus merged commit 38011ad into sindresorhus:master May 1, 2017
@sindresorhus
Copy link
Owner

Looks great. Thank you @MarkTiedemann :)

@sindresorhus
Copy link
Owner

Would you be interested in being a maintainer here? I don't think this module requires much more work, so it's mostly just to highlight your contribution here in the readme.

@MarkTiedemann
Copy link
Contributor Author

Yeah, sure. :) Thanks a lot!

Well, there's some work I'd like to do here in the time to come:

  • Implement the /apps flag
  • Implement the /m module flag
  • Implement the /svc service flag
  • Make a streaming interface available (I already created a prototype at tasklist-stream, but there's more work to be done there, too. And I'm not sure how to "merge" both modules - if they should be merged at all.
  • As per tasklist /?, windowTitle and status filters are not supported when querying a remote machine. I'd like to implement a check for that, and also test whether this case breaks the code of this module in any way.

@sindresorhus
Copy link
Owner

Awesome! Could you put the above into an issue with checklists?

@MarkTiedemann
Copy link
Contributor Author

Yeah, sure. See: #8.

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.

2 participants