This repository has been archived by the owner on Apr 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Very first version of new CLI. * Hook up calling on Windows. * Try for Mac and Linux. Need to test on Mac. * Fix mac path. * Small changes to CLI script. * Fix bin pointing to CLI. * Clarify changes in cli_args. * Update Registry key check. * Update Windows installer to get around path issues. * Update Mac add to PATH command. * Fix logic error.
- Loading branch information
Showing
13 changed files
with
285 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash | ||
|
||
# Get the path to the currently running script: | ||
self=$0 | ||
|
||
# Test if $self is a symlink | ||
if [ -L "$self" ] ; then | ||
# readlink returns the path to the file the link points to: | ||
target=$(readlink "$self") | ||
else | ||
target=$self | ||
fi | ||
|
||
ONI_PATH=$(dirname "$target") | ||
ONI_EXECUTABLE="${ONI_PATH}/../../../../oni" | ||
CLI_SCRIPT="${ONI_PATH}/../../lib/cli/src/cli.js" | ||
|
||
ELECTRON_RUN_AS_NODE=1 "${ONI_EXECUTABLE}" "$CLI_SCRIPT" "$*" | ||
exit $? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash | ||
|
||
# Get the path to the currently running script: | ||
self=$0 | ||
|
||
# Test if $self is a symlink | ||
if [ -L "$self" ] ; then | ||
# readlink returns the path to the file the link points to: | ||
target=$(readlink "$self") | ||
else | ||
target=$self | ||
fi | ||
|
||
ONI_PATH=$(dirname "$target") | ||
ONI_EXECUTABLE="${ONI_PATH}/../../../../MacOS/Oni" | ||
CLI_SCRIPT="${ONI_PATH}/../../lib/cli/src/cli.js" | ||
|
||
ELECTRON_RUN_AS_NODE=1 "${ONI_EXECUTABLE}" "$CLI_SCRIPT" "$*" | ||
exit $? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import * as path from "path" | ||
|
||
import { CLIArgs, parseCLIProcessArgv } from "./cli_args" | ||
|
||
import { spawn } from "child_process" | ||
|
||
export async function main(cli_arguments: string[]): Promise<any> { | ||
// First, try to parse the CLI args and deal with them. | ||
let args: CLIArgs | ||
|
||
try { | ||
args = parseCLIProcessArgv(cli_arguments) | ||
} catch (err) { | ||
process.stdout.write(err.message) | ||
throw err | ||
} | ||
|
||
if (args.help || args.version) { | ||
const version = require(path.join(__dirname, "..", "..", "..", "package.json")).version // tslint:disable-line no-var-requires | ||
process.stdout.write("Oni: Modern Modal Editing - powered by Neovim\n") | ||
process.stdout.write(` version: ${version}\n`) | ||
process.stdout.write("\nUsage:\n oni [FILE]\t\tEdit file\n") | ||
process.stdout.write("\nhttps://github.com/onivim/oni\n") | ||
|
||
return Promise.resolve(true) | ||
} | ||
|
||
// Otherwise, was loaded normally, so launch Oni. | ||
|
||
const env = assign({}, process.env, { | ||
ONI_CLI: "1", // Let Oni know it was started from the CLI | ||
ELECTRON_NO_ATTACH_CONSOLE: "1", | ||
}) | ||
|
||
delete env["ELECTRON_RUN_AS_NODE"] | ||
|
||
const options = { | ||
detached: true, | ||
env, | ||
} | ||
|
||
const child = await spawn(process.execPath, cli_arguments.slice(2), options) | ||
child.unref() | ||
|
||
child.on("close", code => { | ||
if (code !== 0) { | ||
throw Error(`Exit code was ${code}, not 0.`) | ||
} else { | ||
return Promise.resolve(true) | ||
} | ||
}) | ||
|
||
child.on("error", err => { | ||
throw err | ||
}) | ||
|
||
child.on("exit", code => { | ||
if (code && code !== 0) { | ||
throw Error(`Exit code was ${code}, not 0.`) | ||
} else { | ||
return Promise.resolve(true) | ||
} | ||
}) | ||
} | ||
|
||
function assign(destination: any, ...sources: any[]): any { | ||
sources.forEach(source => Object.keys(source).forEach(key => (destination[key] = source[key]))) | ||
return destination | ||
} | ||
|
||
function eventuallyExit(code: number): void { | ||
setTimeout(() => process.exit(code), 0) | ||
} | ||
|
||
main(process.argv) | ||
.then(() => { | ||
eventuallyExit(0) | ||
}) | ||
.then(null, err => { | ||
console.error(err.message || err.stack || err) | ||
eventuallyExit(1) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import * as minimist from "minimist" | ||
|
||
export interface CLIArgs { | ||
help?: boolean | ||
version?: boolean | ||
[arg: string]: any | ||
} | ||
|
||
const options: minimist.Opts = { | ||
boolean: ["help", "version"], | ||
alias: { | ||
help: "h", | ||
version: "v", | ||
}, | ||
} | ||
|
||
export function parseArgs(args: string[]): CLIArgs { | ||
return minimist(args, options) as CLIArgs | ||
} | ||
|
||
// Skip the first 2 arguments as that is the location of the Electron binary, | ||
// and the location of the cli.ts script. | ||
export function parseCLIProcessArgv(processArgv: string[]): CLIArgs { | ||
let [, , ...args] = processArgv | ||
|
||
return parseArgs(args) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"compilerOptions": { | ||
"allowUnreachableCode": false, | ||
"allowUnusedLabels": false, | ||
"experimentalDecorators": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"jsx": "react", | ||
"lib": ["dom", "es2017"], | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"newLine": "LF", | ||
"noEmitOnError": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitReturns": true, | ||
"noImplicitThis": true, | ||
"noUnusedLocals": true, | ||
"outDir": "../lib/cli", | ||
"pretty": true, | ||
"removeComments": true, | ||
"rootDir": ".", | ||
"skipLibCheck": true, | ||
"strictNullChecks": false, | ||
"suppressImplicitAnyIndexErrors": true, | ||
"target": "es2015", | ||
"sourceMap": true | ||
}, | ||
"include": ["src/**/*.ts"], | ||
"exclude": ["node_modules"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@echo off | ||
setlocal | ||
set ELECTRON_RUN_AS_NODE=1 | ||
call "%~dp0..\..\..\..\Oni.exe" "%~dp0..\..\lib\cli\src\cli.js" %* | ||
endlocal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.