Repository: donejs/donejs (js)

Issue:
Add flag for selecting all of the default options
@phillipskevin commented on [Thu Jan 26 2017](https://github.com/donejs/cli/issues/71)

It would be nice if you could do something like

```
donejs add app my-app --yes
```

and have all of the default options selected without having to hit enter for every question.

---

@matthewp commented on [Wed Feb 15 2017](https://github.com/donejs/cli/issues/71#issuecomment-280026990)

Shouldn't this be a generator-donejs issue? You couldn't support this universally, I don't think, like `donejs add firebase --yes` wouldn't work. Hopefully the cli flags are passed to the generator some how, and they can interpret them as they wish.

---

@phillipskevin commented on [Wed Feb 15 2017](https://github.com/donejs/cli/issues/71#issuecomment-280047657)

Actually, this is a donejs/donejs issue first, and then a generator-donejs issue. We need to add a command line flag here: https://github.com/donejs/donejs/blob/master/lib/cli/index.js#L15 or commander will exit with `error: unknown option '--yes'`.



Pull request description:
Add flag to `donejs add` command to use defaults
Closes #819



Patch:
diff --git a/docs/guides/guide.md b/docs/guides/guide.md
index 6431e20..975a62c 100644
--- a/docs/guides/guide.md
+++ b/docs/guides/guide.md
@@ -31,7 +31,7 @@ In this section, we will install DoneJS and generate a new application.
 To get started, let’s install the DoneJS command line utility globally:
 
 ```shell
-npm install -g donejs
+npm install -g donejs@pre
 ```
 
 ### Generate the application
@@ -161,7 +161,7 @@ Then, add a `page` property on the `AppViewModel` and
 define a rule for it in `src/app.js`:
 
 @sourceref ../../guides/guide/steps/7-navigate/app.js
-@highlight 7,14,only
+@highlight 6,13,only
 
 > New APIs Used:
 > - [DefineMap](https://canjs.com/doc/can-define/map/map.html) — used to define observable types.
@@ -204,7 +204,7 @@ On the homepage, let’s install and add [bit-tabs](https://github.com/bitovi-co
 Run:
 
 ```shell
-npm install bit-tabs@2 --save
+npm install bit-tabs@pre --save
 ```
 
 ### Update the page
diff --git a/docs/guides/place-my-order.md b/docs/guides/place-my-order.md
index 3c398fa..d516960 100644
--- a/docs/guides/place-my-order.md
+++ b/docs/guides/place-my-order.md
@@ -29,7 +29,7 @@ You will need [NodeJS](http://nodejs.org) installed and your code editor of choi
 To get started, let's install the DoneJS command line utility globally:
 
 ```shell
-npm install -g donejs
+npm install -g donejs@pre
 ```
 
 Then we can create a new DoneJS application:
@@ -188,7 +188,6 @@ The main application file at `src/app.js` looks like this:
 import DefineMap from 'can-define/map/';
 import route from 'can-route';
 import 'can-route-pushstate';
-import 'can-debug#?./is-dev';
 
 const AppViewModel = DefineMap.extend({
   env: {
@@ -295,7 +294,7 @@ To learn more about routing visit the CanJS guide on [Application State and Rout
 To add our routes, change `src/app.js` to:
 
 @sourceref ../../guides/place-my-order/steps/create-routes/app.js
-@highlight 7-9,17-19,only
+@highlight 6-8,16-18,only
 
 > Notice: We also removed the `message` property in `AppViewModel`.  This is because
 > it is not needed.
@@ -760,7 +759,7 @@ Here we are adding some more conditions if `page` is set to `restaurants`:
 The npm integration of StealJS makes it very easy to share and import other components. One thing we want to do when showing the `pmo-order-new` component is have a tab to choose between the lunch and dinner menu. The good news is that there is already a [bit-tabs](https://github.com/bitovi-components/bit-tabs) component which does exactly that. Let's add it as a project dependency with:
 
 ```shell
-npm install bit-tabs@2 --save
+npm install bit-tabs@pre --save
 ```
 
 And then integrate it into `src/order/new/new.stache`:
diff --git a/guides/guide/steps/7-navigate/app.js b/guides/guide/steps/7-navigate/app.js
index db68e5c..b556ce7 100644
--- a/guides/guide/steps/7-navigate/app.js
+++ b/guides/guide/steps/7-navigate/app.js
@@ -1,7 +1,6 @@
 import DefineMap from 'can-define/map/';
 import route from 'can-route';
 import 'can-route-pushstate';
-import 'can-debug#?./is-dev';
 
 const AppViewModel = DefineMap.extend({
   page: 'string',
diff --git a/guides/place-my-order/steps/create-routes/app.js b/guides/place-my-order/steps/create-routes/app.js
index 7ea74ac..5d4f99e 100644
--- a/guides/place-my-order/steps/create-routes/app.js
+++ b/guides/place-my-order/steps/create-routes/app.js
@@ -1,7 +1,6 @@
 import DefineMap from 'can-define/map/';
 import route from 'can-route';
 import 'can-route-pushstate';
-import 'can-debug#?./is-dev';
 
 const AppViewModel = DefineMap.extend({
   page: 'string',
diff --git a/lib/cli/cmd-init.js b/lib/cli/cmd-init.js
index a583999..e8f2d50 100644
--- a/lib/cli/cmd-init.js
+++ b/lib/cli/cmd-init.js
@@ -49,6 +49,10 @@ function runCliInit(folderPath, options) {
     initArgs.push('--type', options.type);
   }
 
+  if (options.yes) {
+    initArgs.push('--yes');
+  }
+
   options.cwd = folderPath;
   return runBinary(initArgs, options);
 }
diff --git a/lib/cli/index.js b/lib/cli/index.js
index b8507ed..867d948 100644
--- a/lib/cli/index.js
+++ b/lib/cli/index.js
@@ -13,6 +13,7 @@ program.version(require('../../package.json').version);
 // donejs add
 program.command('add <type> [params...]')
   .option('-S, --skip-install')
+  .option('-Y, --yes', 'Use only defaults and not prompt for any option')
   .usage(cmdAddUsage())
   .action(function(type, params, options) {
     log(add(type, params, options));
diff --git a/package.json b/package.json
index d440646..1d30c7d 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "donejs",
-  "version": "2.0.0",
+  "version": "2.0.0-pre.1",
   "description": "Your app is done",
   "main": "./lib/cli/index.js",
   "bin": {


Test patch:
diff --git a/guides/guide/test.js b/guides/guide/test.js
index 0ca4d74..0e3d7ef 100644
--- a/guides/guide/test.js
+++ b/guides/guide/test.js
@@ -166,7 +166,7 @@ guide.step("Install and use bit-tabs", function(){
     return guide.wait(10000);
   }
 
-	return guide.executeCommand("npm", ["install", "bit-tabs@2", "--save"])
+	return guide.executeCommand("npm", ["install", "bit-tabs@pre", "--save"])
     .then(installWait)
 		.then(function(){
 			return guide.replaceFile(join("src", "home.component"),
diff --git a/guides/place-my-order/test.js b/guides/place-my-order/test.js
index 65e9dd9..f9f5f41 100644
--- a/guides/place-my-order/test.js
+++ b/guides/place-my-order/test.js
@@ -357,7 +357,7 @@ guide.step("Create additional components", function(){
 });
 
 guide.step("Importing other projects", function(){
-	return guide.executeCommand("npm", ["install", "bit-tabs@2", "--save"])
+	return guide.executeCommand("npm", ["install", "bit-tabs@pre", "--save"])
 		.then(wait)
 		.then(wait)
 		.then(function(){
diff --git a/test/cmd-init-test.js b/test/cmd-init-test.js
index 1bc8ba2..a3ed635 100644
--- a/test/cmd-init-test.js
+++ b/test/cmd-init-test.js
@@ -105,11 +105,15 @@ describe('cli init cmd', function() {
   });
 
   it('passes options to donejs-init properly', function(done) {
-    init(folder, { skipInstall: true, type: 'foobar' })
+    init(folder, { skipInstall: true, yes: true, type: 'foobar' })
       .then(function() {
-        assert.deepEqual(runBinaryCall.args, [
-          'init', '--skip-install', '--type', 'foobar'
-        ]);
+        var args = runBinaryCall.args;
+
+        assert(includes(args, '--skip-install'));
+        assert(includes(args, '--yes'));
+        assert(includes(args, '--type'));
+        assert(includes(args, 'foobar'));
+
         done();
       })
       .catch(done);
@@ -120,4 +124,8 @@ describe('cli init cmd', function() {
       rimraf.sync(folder);
     }
   }
+
+  function includes(collection, value) {
+    return (collection || []).indexOf(value) !== -1;
+  }
 });