GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — ketool/src/commands/rmdir.ts at v0.1.1 · fixpoint/ketool

Expand file tree

/

rmdir.ts

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
92 lines (73 loc) · 2.52 KB
/

rmdir.ts

Copy path

File metadata and controls

92 lines (73 loc) · 2.52 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import {Args, Command, Flags} from '@oclif/core'
import path from 'node:path'
import * as KeClient from '../client.js'
import {checkCwd, checkInsecure} from '../common.js'
import Config from '../config.js'
import {DIRECTORY_TYPE} from '../const.js'
import {common as commonFlags} from '../flags.js'
type RmdirOptions = {
parent?: boolean
verbose?: boolean
}
export default class Rmdir extends Command {
static override args = {
directory: Args.string({
description: 'path of the directory to be removed',
required: true,
}),
}
static override description = 'Remove the directories, if they are empty.'
static override examples = [
'<%= config.bin %> <%= command.id %>',
]
static override flags = {
...commonFlags,
// flag with a value (-c, --cwd=VALUE)
cwd: Flags.string({char: 'c', description: 'set current working directory to VALUE'}),
parent: Flags.boolean({char: 'p', description: 'remove DIRECTORY and its ancestors'}),
verbose: Flags.boolean({char: 'v', description: 'print a message for each removed directory'}),
}
static strict = false
private conf!: Config
public async run(): Promise<void> {
const {argv, flags} = await this.parse(Rmdir)
this.conf = new Config(flags)
checkInsecure(flags.insecure)
const cwd = await checkCwd(this.conf, flags.cwd)
const results = await Promise.all(
argv.map((arg) => this.removeDirectory(cwd, arg as string, flags))
)
if (results.includes(null)) {
this.exit(1)
}
}
private async removeDirectory(cwd: string, target: string, options: RmdirOptions) {
const targetDir = path.resolve(cwd, target)
const result = await KeClient.get(this.conf, targetDir)
if (result === null) {
this.warn(`failed to remove directory: '${targetDir}' is not found`)
return null
}
if (result.type_object !== DIRECTORY_TYPE) {
this.warn(`failed to remove directory: '${targetDir}' is not a directory`)
return null
}
// ディレクトリが空かどうかチェックする
const results = await KeClient.getChildren(this.conf, targetDir)
if (results!.count > 0) {
this.warn(`failed to remove directory: '${targetDir}' is not empty`)
return null
}
await KeClient.del(this.conf, targetDir)
if (options.verbose) {
this.log(`removed directory: ${targetDir}`)
}
if (options.parent) {
const {dir} = path.parse(targetDir)
if (dir !== cwd) {
await this.removeDirectory(cwd, dir, options)
}
}
return result
}
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.