Skip to content

Commit 730f095

Browse files
committed
Add: put command
1 parent 90eb853 commit 730f095

File tree

12 files changed

+327
-35
lines changed

12 files changed

+327
-35
lines changed

README.md

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ USAGE
3131
<!-- commands -->
3232
* [`ketool help [COMMAND]`](#ketool-help-command)
3333
* [`ketool mkdir DIRECTORY`](#ketool-mkdir-directory)
34+
* [`ketool put SOURCE`](#ketool-put-source)
3435
* [`ketool rm OBJECT`](#ketool-rm-object)
3536
* [`ketool rmdir DIRECTORY`](#ketool-rmdir-directory)
3637

@@ -60,13 +61,14 @@ Create the directories, if they do not already exist.
6061

6162
```
6263
USAGE
63-
$ ketool mkdir DIRECTORY... [-u <value>] [-t <value>] [-c <value>] [-p] [-v]
64+
$ ketool mkdir DIRECTORY... [-u <value>] [-t <value>] [-k] [-c <value>] [-p] [-v]
6465
6566
ARGUMENTS
6667
DIRECTORY... path of the directory to be created
6768
6869
FLAGS
6970
-c, --cwd=<value> set current working directory to VALUE
71+
-k, --insecure allow insecure SSL connection
7072
-p, --parent no error if existing, make parent directories as needed
7173
-t, --token=<value> API access token of the Kompira Enterprise server
7274
-u, --baseurl=<value> base URL of the Kompira Enterprise server
@@ -81,20 +83,51 @@ EXAMPLES
8183

8284
_See code: [src/commands/mkdir.ts](https://github.com/fixpoint/ketool/blob/v0.0.0/src/commands/mkdir.ts)_
8385

86+
## `ketool put SOURCE`
87+
88+
put files or directories to Kompira server
89+
90+
```
91+
USAGE
92+
$ ketool put SOURCE... [-u <value>] [-t <value>] [-k] [-d <value>] [-c <value>] [-r] [-o] [-v]
93+
94+
ARGUMENTS
95+
SOURCE... source file or directory
96+
97+
FLAGS
98+
-c, --cwd=<value> set current working directory to VALUE
99+
-d, --dest=<value> specify destination object or directory (create if none exists)
100+
-k, --insecure allow insecure SSL connection
101+
-o, --overwrite overwrite an existing object
102+
-r, --recursive put directories recursively
103+
-t, --token=<value> API access token of the Kompira Enterprise server
104+
-u, --baseurl=<value> base URL of the Kompira Enterprise server
105+
-v, --verbose explain what is being down
106+
107+
DESCRIPTION
108+
put files or directories to Kompira server
109+
110+
EXAMPLES
111+
$ ketool put
112+
```
113+
114+
_See code: [src/commands/put.ts](https://github.com/fixpoint/ketool/blob/v0.0.0/src/commands/put.ts)_
115+
84116
## `ketool rm OBJECT`
85117

86118
Remove the directories, if they are empty.
87119

88120
```
89121
USAGE
90-
$ ketool rm OBJECT... [-u <value>] [-t <value>] [-c <value>] [-f] [-r] [-v]
122+
$ ketool rm OBJECT... [-u <value>] [-t <value>] [-k] [-c <value>] [-f] [-r] [-v]
91123
92124
ARGUMENTS
93125
OBJECT... path of the object to be removed
94126
95127
FLAGS
96128
-c, --cwd=<value> set current working directory to VALUE
97129
-f, --force ignore nonexistent objects and arguments
130+
-k, --insecure allow insecure SSL connection
98131
-r, --recurcive remove directories and their contents recursively
99132
-t, --token=<value> API access token of the Kompira Enterprise server
100133
-u, --baseurl=<value> base URL of the Kompira Enterprise server
@@ -115,13 +148,14 @@ Remove the directories, if they are empty.
115148

116149
```
117150
USAGE
118-
$ ketool rmdir DIRECTORY... [-u <value>] [-t <value>] [-c <value>] [-p] [-v]
151+
$ ketool rmdir DIRECTORY... [-u <value>] [-t <value>] [-k] [-c <value>] [-p] [-v]
119152
120153
ARGUMENTS
121154
DIRECTORY... path of the directory to be removed
122155
123156
FLAGS
124157
-c, --cwd=<value> set current working directory to VALUE
158+
-k, --insecure allow insecure SSL connection
125159
-p, --parent remove DIRECTORY and its ancestors
126160
-t, --token=<value> API access token of the Kompira Enterprise server
127161
-u, --baseurl=<value> base URL of the Kompira Enterprise server

package-lock.json

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111
"@oclif/core": "^4",
1212
"@oclif/plugin-help": "^6",
1313
"config": "^3.3.12",
14+
"mime-types": "^2.1.35",
1415
"typed-rest-client": "^2.1.0"
1516
},
1617
"devDependencies": {
1718
"@oclif/prettier-config": "^0.2.1",
1819
"@oclif/test": "^4",
1920
"@types/chai": "^4",
2021
"@types/config": "^3.3.5",
22+
"@types/mime-types": "^2.1.4",
2123
"@types/mocha": "^10",
2224
"@types/node": "^18",
2325
"chai": "^4",

src/client.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,31 @@ export namespace KeClient {
6161
return resp.result
6262
}
6363

64-
export async function create(config: Config, path: string, name: string, data: any): Promise<ObjectResponse | null> {
64+
export async function create(config: Config, path: string, data: any): Promise<ObjectResponse> {
6565
let rest: rm.RestClient = new rm.RestClient('ke-client', config.baseurl)
6666
let resp: rm.IRestResponse<ObjectResponse> = await rest.create<ObjectResponse>(path, data, request_options(config.token))
6767
if (resp.statusCode != 201) {
6868
throw new Error(`StatusCode: ${resp.statusCode}`)
6969
}
70-
return resp.result
70+
return resp.result as ObjectResponse
71+
}
72+
73+
export async function update(config: Config, path: string, data: any): Promise<ObjectResponse> {
74+
let rest: rm.RestClient = new rm.RestClient('ke-client', config.baseurl)
75+
let resp: rm.IRestResponse<ObjectResponse> = await rest.update<ObjectResponse>(path, data, request_options(config.token))
76+
if (resp.statusCode != 200) {
77+
throw new Error(`StatusCode: ${resp.statusCode}`)
78+
}
79+
return resp.result as ObjectResponse
80+
}
81+
82+
export async function replace(config: Config, path: string, data: any): Promise<ObjectResponse> {
83+
let rest: rm.RestClient = new rm.RestClient('ke-client', config.baseurl)
84+
let resp: rm.IRestResponse<ObjectResponse> = await rest.replace<ObjectResponse>(path, data, request_options(config.token))
85+
if (resp.statusCode != 200) {
86+
throw new Error(`StatusCode: ${resp.statusCode}`)
87+
}
88+
return resp.result as ObjectResponse
7189
}
7290

7391
export async function del(config: Config, path: string, force: boolean = false): Promise<boolean> {

src/commands/mkdir.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import {Args, Command, Flags} from '@oclif/core'
2-
import {common as common_flags} from '../flags.js'
32
import path from 'path'
3+
4+
import {common as common_flags} from '../flags.js'
45
import Config from '../config.js'
56
import KeClient from '../client.js'
7+
import {check_cwd, check_insecure} from '../common.js'
68
import {DIRECTORY_TYPE} from '../const.js'
79

810

@@ -31,21 +33,14 @@ export default class Mkdir extends Command {
3133

3234
public async run(): Promise<void> {
3335
const {argv, flags} = await this.parse(Mkdir)
34-
let cwd = '/'
35-
if (flags.cwd) {
36-
// cwd のパラメータチェック
37-
if (!path.isAbsolute(flags.cwd)) {
38-
throw new Error(`cwd should be absolute path: ${flags.cwd}`)
39-
}
40-
cwd = flags.cwd
41-
}
4236
const config = new Config(flags)
37+
check_insecure(flags.insecure)
38+
let cwd = await check_cwd(config, flags.cwd)
4339
for (let i = 0; i < argv.length; i++) {
4440
const {dir, base} = path.parse(path.resolve(cwd, argv[i] as string))
4541
await this.make_directory(config, dir, base, flags.parent, flags.verbose)
4642
}
4743
}
48-
4944
private async make_directory(config: Config, parent_dir: string, name: string, parent: boolean = false, verbose: boolean = false) {
5045
// parent_dir の存在チェック
5146
let result = await KeClient.get(config, parent_dir)
@@ -63,7 +58,7 @@ export default class Mkdir extends Command {
6358
'type_object': DIRECTORY_TYPE,
6459
'name': name
6560
}
66-
result = await KeClient.create(config, parent_dir, name, data)
61+
result = await KeClient.create(config, parent_dir, data)
6762
if (result && verbose) {
6863
this.log(`created directory: ${result.abspath}`)
6964
}

0 commit comments

Comments
 (0)