Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
PUBLIC
/
surfer-okd
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit c9d33e20
authored
Mar 01, 2016
by
Johannes Zellner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support last argument as destination
1 parent
cc6510cf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
9 deletions
cli/actions.js
cli/surfer.js
cli/actions.js
View file @
c9d33e2
...
...
@@ -8,6 +8,7 @@ exports.del = del;
var
superagent
=
require
(
'superagent'
),
config
=
require
(
'./config.js'
),
readlineSync
=
require
(
'readline-sync'
),
safe
=
require
(
'safetydance'
),
async
=
require
(
'async'
),
fs
=
require
(
'fs'
),
request
=
require
(
'request'
),
...
...
@@ -28,7 +29,7 @@ function checkConfig() {
gQuery
=
{
username
:
config
.
username
(),
password
:
config
.
password
()
};
console
.
error
(
'Using server %s'
,
config
.
server
().
yellow
);
console
.
error
(
'Using server %s'
,
config
.
server
().
cyan
);
}
function
collectFiles
(
filesOrFolders
,
options
)
{
...
...
@@ -93,6 +94,14 @@ function login(uri) {
function
put
(
filePath
,
otherFilePaths
,
options
)
{
checkConfig
();
var
destination
=
''
;
// take the last argument as destination
if
(
otherFilePaths
.
length
>
0
)
{
destination
=
otherFilePaths
.
pop
();
if
(
otherFilePaths
.
length
>
0
&&
destination
[
destination
.
length
-
1
]
!==
'/'
)
destination
+=
'/'
;
}
var
files
=
collectFiles
([
filePath
].
concat
(
otherFilePaths
),
options
);
async
.
eachSeries
(
files
,
function
(
file
,
callback
)
{
...
...
@@ -106,7 +115,7 @@ function put(filePath, otherFilePaths, options) {
relativeFilePath
=
path
.
basename
(
file
);
}
var
destinationPath
=
(
options
.
destination
?
'/'
+
options
.
destination
:
''
)
+
'/'
+
relativeFilePath
;
var
destinationPath
=
(
destination
?
'/'
+
destination
:
''
)
+
'/'
+
relativeFilePath
;
console
.
log
(
'Uploading file %s -> %s'
,
relativeFilePath
.
cyan
,
destinationPath
.
cyan
);
superagent
.
put
(
config
.
server
()
+
API
+
destinationPath
).
query
(
gQuery
).
attach
(
'file'
,
file
).
end
(
function
(
error
,
result
)
{
...
...
@@ -136,14 +145,19 @@ function get(filePath) {
request
.
get
(
config
.
server
()
+
API
+
filePath
,
{
qs
:
gQuery
},
function
(
error
,
result
,
body
)
{
if
(
error
)
return
console
.
error
(
error
);
if
(
result
.
statusCode
===
401
)
return
console
.
log
(
'Login failed'
);
if
(
result
.
statusCode
===
404
)
return
console
.
log
(
'No such file or directory
'
);
if
(
result
.
statusCode
===
404
)
return
console
.
log
(
'No such file or directory
%s'
,
filePath
.
yellow
);
// 222 indicates directory listing
if
(
result
.
statusCode
===
222
)
{
console
.
log
(
'Files:'
);
JSON
.
parse
(
body
).
entries
.
forEach
(
function
(
entry
)
{
console
.
log
(
'\t %s'
,
entry
);
});
var
files
=
safe
.
JSON
.
parse
(
body
);
if
(
!
files
||
files
.
entries
.
length
===
0
)
{
console
.
log
(
'No files on the server. Use %s to upload some.'
,
'surfer put <file>'
.
yellow
);
}
else
{
console
.
log
(
'Files:'
);
files
.
entries
.
forEach
(
function
(
entry
)
{
console
.
log
(
'\t %s'
,
entry
);
});
}
}
else
{
process
.
stdout
.
write
(
body
);
}
...
...
cli/surfer.js
View file @
c9d33e2
...
...
@@ -15,9 +15,8 @@ program.command('login <url>')
.
action
(
actions
.
login
);
program
.
command
(
'put <file> [files...]'
)
.
option
(
'-d --destination <folder>'
,
'Destination folder. This is prepended to the relative <file> path'
)
.
option
(
'-a --all'
,
'Also include hidden files and folders.'
,
false
)
.
description
(
'Put a file'
)
.
description
(
'Put a file
, last argument is destination if provided
'
)
.
action
(
actions
.
put
);
program
.
command
(
'get [file]'
)
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment