/
skel.ts
55 lines (46 loc) · 1.28 KB
/
skel.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* penguins-eggs
* command: skel.ts
* author: Piero Proietti
* email: piero.proietti@gmail.com
* license: MIT
*/
import {Command, Flags} from '@oclif/core'
import Utils from '../../classes/utils'
import fs from 'fs'
import Xdg from '../../classes/xdg'
export default class Skel extends Command {
static flags = {
help: Flags.help({char: 'h'}),
user: Flags.string({char: 'u', description: 'user to be used'}),
verbose: Flags.boolean({char: 'v'}),
}
static description = 'update skel from home configuration'
static examples = [
'sudo eggs tools skel',
'sudo eggs tools skel --user user-to-be-copied',
]
async run(): Promise<void> {
Utils.titles(this.id + ' ' + this.argv)
const {flags} = await this.parse(Skel)
let verbose = false
if (flags.verbose) {
verbose = true
}
let user = ''
user = flags.user ? flags.user : await Utils.getPrimaryUser()
Utils.warning(`user: ${user}`)
const homeSource = `/home/${user}`
if (!fs.existsSync(homeSource)) {
Utils.error(`User ${user} not exist or not exist a proper home`)
Utils.warning('terminate')
process.exit(0)
}
if (Utils.isRoot()) {
Utils.titles('skel')
Xdg.skel(user, verbose)
} else {
Utils.useRoot(this.id)
}
}
}