Skip to content

Commit 063ea9c

Browse files
author
Robin Radic
committed
init
1 parent 29e36e2 commit 063ea9c

File tree

17 files changed

+490
-165
lines changed

17 files changed

+490
-165
lines changed

1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rm: cannot remove '/dev/null': Permission denied

file.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
asdf

src/commands/r-git/tag.ts

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import { command, CommandArguments, CommandConfig, Dispatcher, inject, InputHelper, Log, option, OutputHelper } from "@radic/console";
2+
import { RConfig } from "../../";
3+
import { ConnectHelper } from "../../helpers/helper.connect";
4+
import { IGitService } from "../../services/service.git";
5+
import { execSync } from "child_process";
6+
import { BaseCommand } from "../../core/commands";
7+
8+
@command(`tag
9+
{version/bump-type:string@which version}
10+
[message:string[]@message]`, 'Git tag with bumping', <CommandConfig> {
11+
onMissingArgument: 'help',
12+
example: `{bold}tag by passing the name{/bold}
13+
r git tag 1.2.3
14+
r git tag v1.44.0-alpha.5
15+
r git tag foobar
16+
17+
{bold}tag using version bump. valid bump-types: major, minor, patch, build{/bold}
18+
r git tag <bump-type>
19+
r git tag minor
20+
21+
{bold}tag using a bump-type as name{/bold}
22+
r git tag minor -n
23+
r git tag minor --no-bump
24+
`
25+
})
26+
export class GitTagCmd extends BaseCommand {
27+
showHelp: () => void
28+
29+
@inject('cli.helpers.output')
30+
out: OutputHelper;
31+
32+
@inject('cli.helpers.input')
33+
ask: InputHelper;
34+
35+
@inject('cli.helpers.connect')
36+
connect: ConnectHelper
37+
38+
@inject('r.log')
39+
log: Log;
40+
41+
@inject('r.config')
42+
config: RConfig
43+
44+
@inject('cli.events')
45+
events: Dispatcher;
46+
47+
@option('n', 'Use this if you want to tag `bump type` names like "major", "minor", etc')
48+
noBump: boolean
49+
50+
@option('p', 'Disables pushing')
51+
noPush: boolean
52+
53+
bumpTypes :string[]= ['major','minor', 'patch', 'build']
54+
55+
async handle(args: CommandArguments, ...argv: any[]) {
56+
this.out.dump({args})
57+
58+
if(!args.version){
59+
return this.returnError('No version or bump-type specified.')
60+
}
61+
62+
if(false == this.bumpTypes.includes(args.version) || this.noBump){
63+
let msg = args.message && args.message.length > 0 ? args.message.join(' ') : 'tagged ' + args.version;
64+
msg = `-m "${msg}"`
65+
this.log.verbose(execSync(`git tag -a ${args.version} ${msg}`).toString('utf8'))
66+
if(this.noPush === false) {
67+
this.log.verbose(execSync(`git push -u origin ${args.version}`).toString())
68+
}
69+
return this.returnOk(`Tagged ${args.version} and pushed it`)
70+
}
71+
72+
let tags = execSync('git tag').toString();
73+
let lastTag = process.argv[2] || tags.split('\n').reverse().filter((val) => val !== '')[0];
74+
let seg = this.config('commands.git.tag.regexp').exec(lastTag);
75+
if(seg === null) throw new Error('Could not parse last tag')
76+
let prefixed = seg[2] === undefined // prefixed with "v"
77+
let suffixed = seg[4] === undefined // suffixed with "-<suffix>.<number>"
78+
let parts:any = {
79+
major: prefixed ? seg[1].substr(1) : seg[2],
80+
minor: prefixed ? seg[3] : seg[3],
81+
patch: suffixed ? seg[5] : seg[4],
82+
suffix: seg[6] || null,
83+
build: seg[7] || null
84+
}
85+
let partsNumKeys = Object.keys(parts).filter(key => key !== 'suffix');
86+
partsNumKeys.forEach(key => parts[key] = parseInt(parts[key]));
87+
console.dir(parts);
88+
console.dir({prefixed, suffixed,seg});
89+
parts[args['bump-type']]++;
90+
partsNumKeys.slice(partsNumKeys.indexOf(args['bump-type'])+1).forEach(key => parts[key] = 0)
91+
parts = Object.values(parts);
92+
let version = [(prefixed ? seg[1][0] : '') + parts[0], parts[1], parts[2]].join('.').concat(suffixed ? '-' + [parts[3], parts[4]].join('.') : '')
93+
console.log({parts, version});
94+
95+
}
96+
97+
98+
}
99+
export default GitTagCmd

src/commands/r-jira.ts

Lines changed: 4 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -4,92 +4,13 @@ import { Credential } from "../database/Models/Credential";
44
import { fileSync } from "tmp";
55
import { readFile, readFileSync, writeFileSync } from "fs";
66

7-
@command('jira', 'remote jira communication')
7+
@command('jira {command}', 'remote jira communication', {
8+
isGroup: true
9+
})
810
export class JiraCmd {
911

10-
@inject('cli.helpers.output')
11-
out: OutputHelper;
12+
handle(args: CommandArguments) {
1213

13-
@inject('cli.helpers.input')
14-
in: InputHelper
15-
16-
@inject('r.log')
17-
log: Log;
18-
19-
async handle(args: CommandArguments) {
20-
let con = await Credential.getDefaultFor('jira')
21-
console.log('a')
22-
if ( ! con ) {
23-
return false;
24-
}
25-
console.log('a')
26-
// Dependencies
27-
const imageToAscii = require("image-to-ascii");
28-
const fs = require('pn/fs')
29-
const svg2png = require('svg2png')
30-
31-
// The path can be either a local path or an url
32-
33-
34-
// Passing options
35-
36-
const api = con.getJiraService();
37-
return new Promise((res, rej) => {
38-
api.listProjects((err: any, projects: any[]) => {
39-
projects.forEach(project => {
40-
41-
Axios.create({
42-
withCredentials: true,
43-
auth : {
44-
username: con.key, password: con.secret
45-
}
46-
})
47-
.get(project.avatarUrls[ '16x16' ])
48-
.then(res => {
49-
50-
res = res.data.toString().replace(/\\r\\n/,'');
51-
let filePath = fileSync({postfix: '.svg'}).name;
52-
let filePath2 = fileSync({postfix: '.png'}).name;
53-
writeFileSync(filePath, res, 'utf-8');
54-
fs.readFile(filePath).then(svg2png).then((buf:Buffer) => fs.writeFile(filePath2, buf))
55-
console.log(readFileSync(filePath2, 'utf-8'));
56-
return Promise.resolve(filePath2);
57-
})
58-
.then(filePath => new Promise((res, rej) => {
59-
console.log({ filePath });
60-
imageToAscii(filePath, {
61-
colored: true,
62-
bg : true,
63-
concat : false,
64-
type: 'svg',
65-
pixels : '█'
66-
}, (err, converted) => {
67-
if ( err ) return rej(err);
68-
res(converted)
69-
})
70-
}))
71-
.then((img: string[][]) => {
72-
console.log({img});
73-
if ( err ) return rej(err);
74-
let texts = [
75-
' id: ' + project.id,
76-
' key: ' + project.key,
77-
' name: ' + project.name,
78-
' type: ' + project.projectTypeKey,
79-
]
80-
let lines: string[] = img.map(con => con.join(''));
81-
for ( let i = 0; i < lines.length; i ++ ) {
82-
console.log(lines[ i ], i < texts.length ? texts[ i ] : '');
83-
}
84-
// console.log(.join(' wit text\n'));
85-
res(projects);
86-
})
87-
.catch(err => this.log.error(err) && rej(err))
88-
89-
})
90-
});
91-
92-
})
9314
}
9415

9516
}

src/commands/r-jira/issues.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { command } from "@radic/console";
2+
@command('issues {command}', 'Issue manager', { isGroup: true })
3+
export class JiraIssuesCmd {
4+
}
5+
export default JiraIssuesCmd

src/commands/r-jira/issues/list.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { command, CommandArguments, option, prepareArguments } from "@radic/console";
2+
import { BaseServiceCommand } from "../../../core/commands";
3+
import { JiraService } from "../../../services/service.jira";
4+
5+
@command(`list
6+
[name:string="asdfrr"@the string for this]
7+
[projects:string[]=["asdf","ffd"]@project key or keys]
8+
[num:number=123@single number]
9+
[nums:number[]=[123,321]@array of numbers]
10+
[bool:boolean=true@signle boolean]
11+
[bools:boolean[]=[true,false,true]@array of booleans]`, 'List issues', {
12+
13+
})
14+
export class JiraIssuesListCmd extends BaseServiceCommand {
15+
@option('c', 'name of credential to use')
16+
credential:string
17+
18+
async handle(args:CommandArguments, argv:string[]){
19+
this.out.dump(args);
20+
const jira = await this.connect.getService<JiraService>('jira', this.credential)
21+
// jira.listIssues();
22+
}
23+
}
24+
export default JiraIssuesListCmd

src/commands/r-jira/projects.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { command, CommandArguments, lazyInject, option } from "@radic/console";
2+
import { BaseCommand } from "../../";
3+
import { ConnectHelper } from "../../helpers/helper.connect";
4+
import { JiraService } from "../../services/service.jira";
5+
import * as _ from "lodash";
6+
7+
@command(`projects`, 'Project manager', {})
8+
export class JiraProjectsCmd extends BaseCommand {
9+
10+
@option('l', 'list projects')
11+
list: boolean
12+
13+
@option('c', 'name of credential to use')
14+
credential: string
15+
16+
@lazyInject('cli.helpers.connect')
17+
protected connect: ConnectHelper;
18+
19+
20+
async handle(args: CommandArguments, argv: string[]) {
21+
const jira = await this.connect.getService<JiraService>('jira', this.credential)
22+
23+
if ( this.list ) {
24+
let projects = await jira.listProjects()
25+
this.out.columns(projects.map(project => _.pick(project, [ 'id', 'key', 'name' ])));
26+
return true;
27+
}
28+
29+
30+
}
31+
32+
33+
}
34+
export default JiraProjectsCmd

src/commands/r-pmove.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { command, CommandArguments, CommandConfig, Dispatcher, lazyInject, Log } from "@radic/console";
2+
import { BaseCommand, RConfig } from "../";
3+
import { basename, join, resolve } from "path";
4+
import * as globule from "globule";
5+
import { renameSync, existsSync, mkdirpSync, moveSync } from "fs-extra";
6+
7+
@command(`pmove
8+
{from:string@path to directory}
9+
{to:string@path to directory}`, <CommandConfig> {})
10+
export class PMoveCmd extends BaseCommand {
11+
12+
@lazyInject('cli.events')
13+
protected events: Dispatcher;
14+
15+
16+
async handle(args: CommandArguments, argv?: string[]) {
17+
let from = resolve(args.from)
18+
let to = resolve(args.to)
19+
if ( ! existsSync(from) ) {
20+
return this.returnError(`argument [from] should be a valid path.`, from)
21+
}
22+
let extensions = this.config.get<string[]>('commands.pmove.extensions', []);
23+
from = join(from, `**/*.{${extensions.join(',')}}`);
24+
let files = globule.find(from);
25+
26+
this.log.verbose(`Found ${files.length} files`, files);
27+
if(await this.ask.confirm(`Are you sure you want to move ${files.length} files to: ${to}`)) {
28+
if ( ! existsSync(to) ) {
29+
mkdirpSync(to);
30+
}
31+
files.forEach(filePath => {
32+
let newFilePath = join(to, basename(filePath))
33+
renameSync(filePath, newFilePath);
34+
this.log.verbose('Moved file', { filePath, newFilePath })
35+
})
36+
return this.returnInfo(`Moved ${files.length} files to: ${to}`)
37+
}
38+
}
39+
}
40+
export default PMoveCmd

src/commands/r-ssh/connect.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ export abstract class RcliSshConnect {
3232
dirs: boolean
3333

3434

35-
bins = {
36-
ssh : 'ssh',
37-
sshfs : 'sshfs',
38-
sshpass: 'sshpass',
39-
umount : 'umount'
40-
}
41-
4235
async handle(args: CommandArguments) {
4336

4437
let io = SSHConnection.interact(),
@@ -58,7 +51,7 @@ export abstract class RcliSshConnect {
5851

5952

6053
mount(target: SSHConnection) {
61-
let cmd: string = `${this.config('ssh.bins.sshfs')} ${target.user}@${target.host}:${target.hostPath} ${target.localPath} -p ${target.port}`;
54+
let cmd: string = `${this.config('commands.ssh.bins.sshfs')} ${target.user}@${target.host}:${target.hostPath} ${target.localPath} -p ${target.port}`;
6255
let opts:string = ' -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o reconnect -o workaround=rename';
6356
if ( target.method === 'password' ) {
6457
cmd = `echo ${target.password} | ${cmd} ${opts} -o password_stdin`
@@ -75,7 +68,7 @@ export abstract class RcliSshConnect {
7568
}
7669

7770
umount(target: SSHConnection) {
78-
let cmd: string = `sudo ${this.config('ssh.bins.umount')} ${target.localPath} -f`;
71+
let cmd: string = `sudo ${this.config('commands.ssh.bins.umount')} ${target.localPath} -f`;
7972
execSync(cmd);
8073
rmdirSync(target.localPath);
8174
this.log.info(`Unmounted ${target.localPath} success`);
@@ -84,12 +77,12 @@ export abstract class RcliSshConnect {
8477
ssh(target: SSHConnection) {
8578
let cmd = '';
8679
if ( target.method === 'password' ) {
87-
cmd = `${this.config('ssh.bins.sshpass')} -p ${target.password} `
80+
cmd = `${this.config('commands.ssh.bins.sshpass')} -p ${target.password} `
8881

8982
}
9083

9184
// this.log.info(`attempting SSH connection using -o StrictHostKeyChecking=no ${target.user}@${target.host} -p ${target.port}`)
92-
cmd += `${this.bins.ssh} -o StrictHostKeyChecking=no ${target.user}@${target.host} -p ${target.port}`;
85+
cmd += `${this.config('commands.ssh.bins.ssh')} -o StrictHostKeyChecking=no ${target.user}@${target.host} -p ${target.port}`;
9386

9487
execSync(cmd, {
9588
stdio: 'inherit'

0 commit comments

Comments
 (0)