diff options
Diffstat (limited to 'cli')
-rw-r--r-- | cli/actions.js | 21 | ||||
-rwxr-xr-x | cli/surfer.js | 2 |
2 files changed, 18 insertions, 5 deletions
diff --git a/cli/actions.js b/cli/actions.js index d10e154..8a8624e 100644 --- a/cli/actions.js +++ b/cli/actions.js | |||
@@ -180,16 +180,27 @@ function get(filePath) { | |||
180 | // }); | 180 | // }); |
181 | } | 181 | } |
182 | 182 | ||
183 | function del(filePath) { | 183 | function del(filePath, options) { |
184 | checkConfig(); | 184 | checkConfig(); |
185 | 185 | ||
186 | var query = safe.JSON.parse(safe.JSON.stringify(gQuery)); | ||
187 | query.recursive = options.recursive; | ||
188 | query.dryRun = options.dryRun; | ||
189 | |||
186 | var relativeFilePath = path.resolve(filePath).slice(process.cwd().length + 1); | 190 | var relativeFilePath = path.resolve(filePath).slice(process.cwd().length + 1); |
187 | superagent.del(config.server() + API + relativeFilePath).query(gQuery).end(function (error, result) { | 191 | superagent.del(config.server() + API + relativeFilePath).query(query).end(function (error, result) { |
188 | if (error && error.status === 401) return console.log('Login failed'); | 192 | if (error && error.status === 401) return console.log('Login failed'.red); |
189 | if (error && error.status === 404) return console.log('No such file or directory'); | 193 | if (error && error.status === 404) return console.log('No such file or directory'); |
190 | if (error && error.status === 403) return console.log('No such file or directory'); | 194 | if (error && error.status === 403) return console.log('Failed. Target is a directory. Use %s to delete directories.', '--recursive'.yellow); |
191 | if (error) return console.log('Failed', result ? result.body : error); | 195 | if (error) return console.log('Failed', result ? result.body : error); |
192 | 196 | ||
193 | console.log('Success. Removed %s files.', result.body.entries.length); | 197 | if (options.dryRun) { |
198 | console.log('This would remove %s files:', result.body.entries.length); | ||
199 | result.body.entries.forEach(function (entry) { | ||
200 | console.log('\t %s', entry); | ||
201 | }); | ||
202 | } else { | ||
203 | console.log('Success. Removed %s files.', result.body.entries.length); | ||
204 | } | ||
194 | }); | 205 | }); |
195 | } | 206 | } |
diff --git a/cli/surfer.js b/cli/surfer.js index 278724d..4c096d3 100755 --- a/cli/surfer.js +++ b/cli/surfer.js | |||
@@ -24,6 +24,8 @@ program.command('get [file]') | |||
24 | .action(actions.get); | 24 | .action(actions.get); |
25 | 25 | ||
26 | program.command('del <file>') | 26 | program.command('del <file>') |
27 | .option('-r --recursive', 'Recursive delete directories.', false) | ||
28 | .option('-d --dry-run', 'Only list files to delete.', false) | ||
27 | .description('Delete a file or directory') | 29 | .description('Delete a file or directory') |
28 | .action(actions.del); | 30 | .action(actions.del); |
29 | 31 | ||