Skip to content
This repository has been archived by the owner on Oct 6, 2024. It is now read-only.

Commit

Permalink
add -h flag
Browse files Browse the repository at this point in the history
  • Loading branch information
GreenDjango committed Feb 26, 2020
1 parent 278af9c commit 2ffc216
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 10 deletions.
15 changes: 6 additions & 9 deletions prod/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ exports.run = () => __awaiter(void 0, void 0, void 0, function* () {
while (!should_quit) {
choice = yield ui_1.ask_list(['Repositories management', 'Key management', 'Contact', 'Option', 'Exit'], "Let's do some works");
switch (choice) {
/*TODO: case 'Git clone':
await repo_menu(api, config)
break*/
case 'Repositories management':
yield repository_menu_1.repo_menu(api, config);
break;
Expand Down Expand Up @@ -189,27 +192,21 @@ function parse_args(args, config) {
return __awaiter(this, void 0, void 0, function* () {
if (args[2]) {
if (args[2] === '-h' || args[2] === '-H' || args[2] === '--help') {
show_help();
yield utils_1.sh_live('man blih_cli');
process.exit(0);
}
if (args[2] === '-v' || args[2] === '-V' || args[2] === '--version') {
console.log('v' + utils_1.APP_VERSION);
process.exit(0);
}
if (args[2] === '-u' || args[2] === '-U' || args[2] === '--update' || args[2] === '--UPDATE') {
const spinner = ora_1.default().start(chalk_1.default.green('Check for update...'));
const res = yield utils_1.sh(`sudo sh ${__dirname}/../update.sh 2>&1`);
spinner.stop();
console.log(res.stdout.slice(0, -1));
yield utils_1.sh_live(`sudo sh ${__dirname}/../update.sh`);
process.exit(0);
}
}
config.args = args;
});
}
function show_help() {
ora_1.default().info(chalk_1.default.blue('Invalid option\n Usage blih_cli -[ica] [OPTION]...' +
'\n\n -i interactive mode, default mode' +
'\n -c create new repository' +
'\n -a [REPO], --acl=REPO change repository acl'));
ora_1.default().info(chalk_1.default.blue('Invalid option\n Usage blih_cli -[aci] [OPTION]...' + '\n or use `man blih_cli`'));
}
2 changes: 1 addition & 1 deletion prod/blih_api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"use strict";
// MIT https://www.npmjs.com/package/blih
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
Expand All @@ -15,6 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true });
const crypto_1 = __importDefault(require("crypto"));
const axios_1 = __importDefault(require("axios"));
// MIT https://www.npmjs.com/package/blih
const options = {
baseURL: 'https://blih.epitech.eu/',
timeout: 10000,
Expand Down
110 changes: 110 additions & 0 deletions prod/git_menu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
"use strict";
/*
TODO:
import ora from 'ora'
import chalk from 'chalk'
import { homedir } from 'os'
import fs from 'fs'
import { BlihApi } from './blih_api'
import { ask_list, ask_question, ask_path, ask_input } from './ui'
import { WAIT_MSG, sh } from './utils'
const HOME_DIR = homedir()
export async function git_menu(api: BlihApi) {
let should_quit = false
while (!should_quit) {
const choices = ['↵ Back', 'Git clone my repo', 'Other repo']
const choice = await ask_list(choices, 'Repository')
switch (choice) {
case choices[1]:
await add_key(api)
break
case choices[2]:
await delete_key(api)
break
case choices[0]:
default:
should_quit = true
}
}
}
async function add_key(api: BlihApi) {
const new_ssh = await ask_question('Create new ssh key ?')
const spinner = ora()
spinner.color = 'blue'
try {
let path = ''
if (new_ssh) {
let name = 'epitech_key'
if (fs.existsSync(`${HOME_DIR}/.ssh/${name}.pub`)) {
do {
name = await ask_input(`${name} already exist, new Key name ?`)
} while (fs.existsSync(`${HOME_DIR}/.ssh/${name}.pub`))
}
if (!fs.existsSync(`${HOME_DIR}/.ssh`)) {
fs.mkdirSync(`${HOME_DIR}/.ssh`)
}
spinner.start(chalk.green(WAIT_MSG))
await sh(`ssh-keygen -f ${HOME_DIR}/.ssh/${name} -N ""`)
await sh(`ssh-add ${HOME_DIR}/.ssh/${name}`)
path = `${HOME_DIR}/.ssh/${name}.pub`
} else {
const input = await ask_path('Ssh key path:', '\\.pub$', `${HOME_DIR}/`)
spinner.info(chalk.blue('Use `ssh-add ' + input + '` for enable the key'))
path = input
spinner.start(chalk.green(WAIT_MSG))
}
let key = fs.readFileSync(path, 'utf8')
key = key.replace('\n', '')
const res = await api.uploadKey(key)
spinner.succeed(chalk.green(res))
} catch (err) {
spinner.fail(chalk.red(err))
}
}
async function delete_key(api: BlihApi) {
const spinner = ora().start(chalk.green(WAIT_MSG))
spinner.color = 'blue'
try {
const key_list = await api.listKeys()
spinner.stop()
const choice = await ask_list(
['↵ Back', ...key_list.map(value => value.name + ' ...' + value.data.substr(-20))],
'Select a key'
)
if (choice === '↵ Back' || !(await ask_question('Are you sure ?'))) return
const key = choice.split(' ')[0]
spinner.start(chalk.green(WAIT_MSG))
const res = await api.deleteKey(key)
spinner.succeed(chalk.green(res))
} catch (err) {
spinner.fail(chalk.red(err))
}
}
async function show_key(api: BlihApi) {
const spinner = ora().start(chalk.green(WAIT_MSG))
spinner.color = 'blue'
try {
const key_list = await api.listKeys()
spinner.stop()
const idx = await ask_list(
['↵ Back', ...key_list.map(value => value.name + ' ...' + value.data.substr(-20))],
undefined,
true
)
if (idx === '0') return
const key = key_list[+idx - 1]
spinner.info(chalk.blue(`Name: ${key.name}` + `\n Data: ${key.data}`))
} catch (err) {
spinner.fail(chalk.red(err))
}
}
*/
1 change: 1 addition & 0 deletions prod/repository_menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function create_repo(api, config, repo_name) {
spinner.succeed(chalk_1.default.green(res2) + ' ' + acl_to_string({ name: to_change[0], rights: to_change[1] }));
to_change = yield acl_menu(acl_list, config);
}
//TODO: if (await ask_question(`Git clone ${input} ?`)) 1
}
catch (err) {
spinner.fail(chalk_1.default.red(err));
Expand Down
20 changes: 20 additions & 0 deletions prod/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,23 @@ function sh(cmd) {
});
}
exports.sh = sh;
function sh_live(cmd) {
return __awaiter(this, void 0, void 0, function* () {
return new Promise(function (resolve, reject) {
var _a, _b;
const child = child_process_1.exec(cmd, (err, stdout, stderr) => {
if (err)
reject(err);
else
resolve({ stdout, stderr });
});
(_a = child.stdout) === null || _a === void 0 ? void 0 : _a.on('data', data => {
process.stdout.write(data);
});
(_b = child.stderr) === null || _b === void 0 ? void 0 : _b.on('data', data => {
process.stderr.write(data);
});
});
});
}
exports.sh_live = sh_live;

0 comments on commit 2ffc216

Please sign in to comment.