Question: I have a question regarding a select mysql query. Lets say that we have 2 tables

users: [ id, username ]
logs [ id, user\_id, action ]

I want to selecr all users from table users with the count(`id`) of table logs based on user\_id

I tried to do the following:

```
SELECT t1.*,count(t2.`id`) 
FROM `users` t1
LEFT JOIN `logs` t2 
ON  t1.id = t2.user_id;

```

But that only prints the users who have count logs > 0. I want to select all the users with the count of the logs.

Answer: 
Here's a quick recipe I found:

gulpfile.js
-----------

```
var gulp   = require('gulp');

// npm install gulp yargs gulp-if gulp-uglify
var args   = require('yargs').argv;
var gulpif = require('gulp-if');
var uglify = require('gulp-uglify');

var isProduction = args.env === 'production';

gulp.task('scripts', function() {
  return gulp.src('**/*.js')
    .pipe(gulpif(isProduction, uglify())) // only minify if production
    .pipe(gulp.dest('dist'));
});

```

CLI
---

```
gulp scripts --env production

```

Original Ref (not available anymore): <https://github.com/gulpjs/gulp/blob/master/docs/recipes/pass-params-from-cli.md> 

Alternative with minimist
=========================

From Updated Ref: <https://github.com/gulpjs/gulp/blob/master/docs/recipes/pass-arguments-from-cli.md>

gulpfile.js
-----------

```
// npm install --save-dev gulp gulp-if gulp-uglify minimist

var gulp = require('gulp');
var gulpif = require('gulp-if');
var uglify = require('gulp-uglify');

var minimist = require('minimist');

var knownOptions = {
  string: 'env',
  default: { env: process.env.NODE_ENV || 'production' }
};

var options = minimist(process.argv.slice(2), knownOptions);

gulp.task('scripts', function() {
  return gulp.src('**/*.js')
    .pipe(gulpif(options.env === 'production', uglify())) // only minify if production
    .pipe(gulp.dest('dist'));
});

```

CLI
---

```
gulp scripts --env production

```
If you've some strict (ordered!) arguments, then you can get them simply by checking `process.argv`.

```
var args = process.argv.slice(2);

if (args[0] === "--env" && args[1] === "production");

```

Execute it: `gulp --env production`

...however, I think that this is *tooo* strict and not bulletproof! So, I fiddled a bit around... and ended up with this utility function:

```
function getArg(key) {
  var index = process.argv.indexOf(key);
  var next = process.argv[index + 1];
  return (index < 0) ? null : (!next || next[0] === "-") ? true : next;
}

```

It eats an argument-name and will search for this in `process.argv`. If nothing was found it spits out `null`. Otherwise if their is no next argument or the next argument is a command and not a value (we differ with a dash) `true` gets returned. (That's because the key exist, but there's just no value). If all the cases before will fail, the next argument-value is what we get.

**`> gulp watch --foo --bar 1337 -boom "Foo isn't equal to bar."`**

```
getArg("--foo") // => true
getArg("--bar") // => "1337"
getArg("-boom") // => "Foo isn't equal to bar."
getArg("--404") // => null

```

Ok, enough for now... Here's a simple example using *gulp*:

```
var gulp = require("gulp");
var sass = require("gulp-sass");
var rename = require("gulp-rename");

var env = getArg("--env");

gulp.task("styles", function () {
  return gulp.src("./index.scss")
  .pipe(sass({
    style: env === "production" ? "compressed" : "nested"
  }))
  .pipe(rename({
    extname: env === "production" ? ".min.css" : ".css"
  }))
  .pipe(gulp.dest("./build"));
});

```

Run it `gulp --env production`