-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathskel.ts
55 lines (43 loc) · 1.33 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
/**
* ./src/commands/tools/skel.ts
* penguins-eggs v.10.0.0 / ecmascript 2020
* author: Piero Proietti
* email: piero.proietti@gmail.com
* license: MIT
*/
import { Command, Flags } from '@oclif/core'
import fs from 'node:fs'
import Utils from '../../classes/utils.js'
import Xdg from '../../classes/xdg.js'
export default class Skel extends Command {
static description = 'update skel from home configuration'
static examples = ['sudo eggs tools skel', 'sudo eggs tools skel --user user-to-be-copied']
static flags = {
help: Flags.help({ char: 'h' }),
user: Flags.string({ char: 'u', description: 'user to be used' }),
verbose: Flags.boolean({ char: 'v' })
}
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)
}
}
}