Skip to content

Commit

Permalink
fix checking no argument was specified
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Oct 10, 2017
1 parent c1c9aeb commit 2a58337
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
10 changes: 1 addition & 9 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const child_process = require('child_process');
const electron = require('electron');
const join = require('path').join;
const existsSync = require('fs').existsSync;

const argv = [join(__dirname, '..')];

Expand Down Expand Up @@ -56,14 +55,7 @@ const len = process.argv.length;
// First is 'node' and Second arg is '/path/to/bin/shiba'.
// If user specifies argument, the length of argv must be more than 2.
if (len > 2) {
const last_arg = process.argv[len-1];
if (existsSync(last_arg)) {
argv.push(last_arg);
} else {
argv.push(process.cwd());
}
} else {
argv.push(process.cwd());
argv.push(process.argv[len-1]);
}

if (detached && !version) {
Expand Down
8 changes: 5 additions & 3 deletions browser/initial_path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as fs from 'fs';
import * as path from 'path';

export = function(): string {
function defaultPath(): string {
function defaultPath() {
const cwd = process.cwd();
if (process.platform === 'darwin' && cwd === '/') {
const doc_dir = path.join(process.env.HOME, 'Documents');
Expand All @@ -16,15 +16,17 @@ export = function(): string {
}

// Note:
// First argument is a path to Shiba app
if (process.argv.length < 2) {
// First argument is a path to Electron binary and second one is a path to Shiba app directory.
// So argv.length <= 2 means no path was specified.
if (process.argv.length <= 2) {
return defaultPath();
}

const last_arg = process.argv[process.argv.length - 1];
if (fs.existsSync(last_arg)) {
return path.resolve(last_arg);
} else {
console.log(`Specified path '${last_arg}' not found. Ignored.`);
return defaultPath();
}
};
Expand Down

0 comments on commit 2a58337

Please sign in to comment.