Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Victoria Jeffrey committed Aug 31, 2016
1 parent 33f4fdf commit b9027f0
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 88 deletions.
2 changes: 1 addition & 1 deletion tasks/command_simulator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

# save the result and put it in inspec/www/app/results with the keyname as filename
result = cmd.stdout
dir = 'www/app/responses/'
dir = 'www/tutorial/app/responses/'
out_file = File.new(File.join(dir, "#{keyname}.txt"), 'w')
out_file.puts(result)
out_file.close
Expand Down
6 changes: 4 additions & 2 deletions www/tutorial/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
/node_modules
npm-debug.log

*.js
*.js.map
app/*.js
app/*.js.map
app/xterm-terminal/*.js
app/xterm-terminal/*.js.map
5 changes: 4 additions & 1 deletion www/tutorial/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## InSpec Demo

run `npm install` to load dependencies
run `npm start` to load demo in your browser
run `npm start` to load demo in your browser

To generate content for the app/responses folder,
run `bundle exec rake update demo` from the root of inspec project.
7 changes: 3 additions & 4 deletions www/tutorial/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<div class="terminal-nav">
<!--TODO: make these functional-->
<span> < </span>
<span> > </span>
<span (click)="updateInstructions('prev')"> < </span>
<span (click)="updateInstructions('next')"> > </span>
<span> x </span>
</div>

Expand All @@ -24,5 +23,5 @@
</div>

<div class="cli">
<xterm-terminal (stepNumber)="updateInstructions(stepNumber=$event)" [responsesArray]="responsesArray"></xterm-terminal>
<xterm-terminal (command)="evalCommand(command=$event)" [responsesArray]="responsesArray" [response]="response" [shell]="shell"></xterm-terminal>
</div>
2 changes: 1 addition & 1 deletion www/tutorial/app/app.component.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 75 additions & 6 deletions www/tutorial/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export class AppComponent implements OnInit {
instructions: any;
instructionsArray: any;
responsesArray: any;
counter: number;
counter: number = 0;
response: string;
shell: string;

constructor(private http: Http) { }

Expand All @@ -26,11 +28,77 @@ export class AppComponent implements OnInit {
}

updateInstructions(step) {
if (step < 0) {
step = 0
let totalSteps = this.instructionsArray.length - 1;
if (step === 'next' && this.counter < totalSteps) {
this.counter += 1;
}
else if (step === 'prev' && this.counter > 0) {
this.counter -= 1;
}
else {
this.counter = 0;
}

this.instructions = this.instructionsArray[this.counter]['_body'];
}

evalCommand(command) {
// play with inspec shell
if (this.shell === 'inspec-shell') {
this.parseInspecShell(command);
}
// match on various commands or print inspec help
else {
if (command === 'inspec shell') {
this.shell = 'inspec-shell'
this.response = 'Welcome to the InSpec Shell\n To find out how to use it, type: help\n';
}
else if (command.match(/^inspec\s*exec\s*.*/)) {
this.parseInspecExec(command);
}
else if (command.match(/^inspec\s*version\s*/)) {
this.response = this.responsesArray[4]['_body'];
}
else if (command.match(/^next\s*/)) {
this.updateInstructions('next');
}
else if (command.match(/^prev\s*/)) {
this.updateInstructions('prev');
}
else if (command.match(/^ls\s*/)) {
this.response = this.responsesArray[1]['_body'];
}
else if (command.match(/^pwd\s*/)) {
this.response = this.responsesArray[2]['_body'];
}
else {
this.response = this.responsesArray[0]['_body'];
}
}
}

parseInspecExec(command) {
let target = command.match(/^inspec exec\s*(.*)/);
if (target[1] === 'examples/profile') {
this.response = this.responsesArray[3]['_body'];
} else {
this.response = "Could not fetch inspec profile in '" + target[1] + "' ";
}
}

parseInspecShell(command) {
// exit inspec shell
if (command.match(/^exit\s*/)) {
this.shell = '';
this.response = '';
}
else if (command.match(/^ls\s*/)) {
this.response = this.responsesArray[5]['_body'];
}
// TODO: functionality for inspec Shell
else {
this.response = 'soon this will work, but not yet :) '
}
this.counter = step;
this.instructions = this.instructionsArray[step]['_body'];
}

getInstructions() {
Expand All @@ -53,7 +121,8 @@ export class AppComponent implements OnInit {
this.http.get('/app/responses/ls.txt'), // 1
this.http.get('/app/responses/pwd.txt'), // 2
this.http.get('/app/responses/inspec_exec.txt'), // 3
this.http.get('/app/responses/inspec_version.txt') // 4
this.http.get('/app/responses/inspec_version.txt'), // 4
this.http.get('/app/responses/pwd_inspec_shell.txt') // 5
).subscribe(
data => {
this.responsesArray = data;
Expand Down
1 change: 1 addition & 0 deletions www/tutorial/app/responses/pwd_inspec_shell.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
anonymous-web-user/inspec-shell
Loading

0 comments on commit b9027f0

Please sign in to comment.