GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 1bca6a...c7b116 )
by Stefano
02:33
created

program.action   C

Complexity

Conditions 8
Paths 14

Size

Total Lines 83

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 8
c 1
b 0
f 0
nc 14
nop 1
dl 0
loc 83
rs 5.8854

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
var program = require('commander');
2
var shell = require('shelljs');
3
var chalk = require('chalk');
4
var co = require('co');
5
var prompt = require('co-prompt');
6
7
  // .arguments('<file>')
8
  // .option('-u, --username <username>', 'The user to authenticate as')
9
  // .option('-p, --password <password>', 'The user\'s password')
10
program
11
  .usage('[options] <enviroment ...>')
12
  // .option('-u, --username <username>', 'The user to authenticate as')
13
  .arguments('<enviroment>')
14
  .action(function(enviroment) {
15
16
    shell.mkdir('-p',['applications/assets/icons']);
17
18
    shell.echo('Build Server Vagrant ('+enviroment+')');
19
20
    if ( enviroment === 'dev' ){
21
22
      var vagrantId = shell.exec("vagrant global-status | grep d1b0server | awk '{ print $1}'", {silent:true});
23
24
      var vagrantCode;
25
      if ( vagrantId.code !== 0 ){
26
        //ERRORE
27
        process.stderr.write(chalk.red("Errore: "+vagrantId.stderr+ " - "+vagrantId.output));
28
        process.exit(1);
0 ignored issues
show
Compatibility Debugging Code Best Practice introduced by
Use of process.exit() is discouraged as it will potentially stop the complete node.js application. Consider quitting gracefully instead by throwing an Error.
Loading history...
29
      } else {
30
        vagrantCode = vagrantId.output.trim();
31
      }
32
33
      if ( !vagrantCode ) {
34
        process.stdout.write(chalk.bold.cyan("Vagrant server not found")+"\n");
35
36
        shell.exec('./scripts/generatekey.sh');
37
        shell.exec('./scripts/generateSSL.sh');
38
        shell.exec('./scripts/roles_update.sh');
39
40
        shell.cd('server/');
41
42
        var upVagrant = shell.exec("vagrant up", {silent:true});
43
        if ( upVagrant.code !== 0 ){
44
          //ERRORE
45
          process.stderr.write(chalk.red("Errore: "+upVagrant.stderr+ " - "+upVagrant.output));
46
          process.exit(1);
0 ignored issues
show
Compatibility Debugging Code Best Practice introduced by
Use of process.exit() is discouraged as it will potentially stop the complete node.js application. Consider quitting gracefully instead by throwing an Error.
Loading history...
47
        }
48
49
        process.stdout.write("Vagrant server UP.\n");
50
51
        shell.echo('Install Server Required Package and Config');
52
        var ansibleProc = shell.exec('ansible-playbook -i '+enviroment+'.hosts site.yml');
53
        if ( ansibleProc.code !== 0 ){
54
          //ERRORE
55
          process.stderr.write(chalk.red("Errore ... "));
56
          process.exit(1);
0 ignored issues
show
Compatibility Debugging Code Best Practice introduced by
Use of process.exit() is discouraged as it will potentially stop the complete node.js application. Consider quitting gracefully instead by throwing an Error.
Loading history...
57
        }
58
59
        process.stdout.write("Vagrant server installation packages completed.\n");
60
61
        shell.cd('..');
62
63
      } else {
64
        process.stdout.write("Find vagrant server: "+vagrantCode+". Skip creation.\n");
65
        // non funziona vagrant up by name or uuid
66
        // var upVagrant = shell.exec("vagrant up "+vagrantCode);
67
68
        shell.cd('server/');
69
70
        var upVagrant = shell.exec("vagrant up", {silent:true});
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable upVagrant already seems to be declared on line 42. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
71
        if ( upVagrant.code !== 0 ){
72
          //ERRORE
73
          process.stderr.write(chalk.red("Errore: "+upVagrant.stderr+ " - "+upVagrant.output));
74
          process.exit(1);
0 ignored issues
show
Compatibility Debugging Code Best Practice introduced by
Use of process.exit() is discouraged as it will potentially stop the complete node.js application. Consider quitting gracefully instead by throwing an Error.
Loading history...
75
        }
76
77
        process.stdout.write("Vagrant server UP.\n");
78
79
        shell.cd('..');
80
      }
81
82
    } else {
83
84
        shell.echo('Install Server Required Package and Config');
85
        var ansibleProc = shell.exec('ansible-playbook -i '+enviroment+'.hosts site.yml', {silent:true});
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable ansibleProc already seems to be declared on line 52. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
86
        if ( ansibleProc.code !== 0 ){
87
          //ERRORE
88
          process.stderr.write(chalk.red("Errore ... "));
89
          process.exit(1);
0 ignored issues
show
Compatibility Debugging Code Best Practice introduced by
Use of process.exit() is discouraged as it will potentially stop the complete node.js application. Consider quitting gracefully instead by throwing an Error.
Loading history...
90
        }
91
92
        shell.echo('Completed');
93
94
    }
95
96
  })
97
  .parse(process.argv);
98
99
100
if (!process.argv.slice(2).length) {
101
  program.outputHelp(make_red);
102
}
103
104
function make_red(txt) {
105
  return chalk.red(txt); //display the help text in red on the console
106
}
107
108
//console.log(shell.pwd());
109