This repository has been archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
License: MIT Signed-off-by: achingbrain <[email protected]>
- Loading branch information
1 parent
cb0135c
commit 1577094
Showing
13 changed files
with
371 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict' | ||
|
||
module.exports = { | ||
command: 'mv <source> <dest>', | ||
|
||
describe: 'Move files around. Just like traditional unix mv', | ||
|
||
builder: { | ||
parents: { | ||
alias: 'p', | ||
type: 'boolean', | ||
default: false, | ||
describe: 'Create any non-existent intermediate directories' | ||
}, | ||
recursive: { | ||
alias: 'r', | ||
type: 'boolean', | ||
default: false, | ||
describe: 'Remove directories recursively' | ||
} | ||
}, | ||
|
||
handler (argv) { | ||
let { | ||
source, | ||
dest, | ||
ipfs, | ||
parents, | ||
recursive | ||
} = argv | ||
|
||
ipfs.mfs.mv(source, dest, { | ||
parents, | ||
recursive | ||
}, (error) => { | ||
if (error) { | ||
throw error | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict' | ||
|
||
const promisify = require('promisify-es6') | ||
const series = require('async/series') | ||
const { | ||
toSources | ||
} = require('./utils') | ||
const cp = require('./cp') | ||
const rm = require('./rm') | ||
|
||
const defaultOptions = { | ||
parents: false, | ||
recursive: false, | ||
flush: true, | ||
format: 'dag-pb', | ||
hashAlg: 'sha2-256' | ||
} | ||
|
||
module.exports = function mfsCp (ipfs) { | ||
return promisify(function () { | ||
const { | ||
callback | ||
} = toSources(Array.prototype.slice.call(arguments), defaultOptions) | ||
|
||
// remove the callback | ||
const cpArgs = Array.prototype.slice.call(arguments) | ||
.filter(arg => typeof arg !== 'function') | ||
|
||
// remove the last string in the args as it'll be the destination | ||
const lastStringIndex = cpArgs.reduce((acc, curr, index) => { | ||
if (typeof curr === 'string') { | ||
return index | ||
} | ||
|
||
return acc | ||
}, -1) | ||
const rmArgs = cpArgs | ||
.filter((arg, index) => index !== lastStringIndex) | ||
.slice(0, cpArgs.length - 1) | ||
|
||
series([ | ||
(cb) => cp(ipfs).apply(null, cpArgs.concat(cb)), | ||
(cb) => rm(ipfs).apply(null, rmArgs.concat(cb)) | ||
], callback) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict' | ||
|
||
const toSources = require('./to-sources') | ||
|
||
function toSourcesAndDestination (args, defaultOptions) { | ||
const { | ||
sources, | ||
options, | ||
callback | ||
} = toSources(args, defaultOptions) | ||
|
||
const destination = sources.pop() | ||
|
||
return { | ||
sources, | ||
destination, | ||
options, | ||
callback | ||
} | ||
} | ||
|
||
module.exports = toSourcesAndDestination |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict' | ||
|
||
const path = require('path') | ||
|
||
function toSources (args, defaultOptions) { | ||
args = args.slice() | ||
const callback = args.filter(arg => typeof arg === 'function').pop() | ||
const options = Object.assign({}, defaultOptions, args.filter(arg => typeof arg === 'object').pop() || {}) | ||
|
||
const sources = args | ||
.filter(arg => typeof arg === 'string') | ||
.map(source => { | ||
source = source.trim() | ||
|
||
return { | ||
path: source, | ||
name: path.basename(source), | ||
dir: path.dirname(source) | ||
} | ||
}) | ||
|
||
return { | ||
sources, | ||
options, | ||
callback | ||
} | ||
} | ||
|
||
module.exports = toSources |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.