Skip to content

Commit 2af5281

Browse files
committed
Add --help and -h cli arguments
1 parent d7ff2d6 commit 2af5281

2 files changed

Lines changed: 53 additions & 3 deletions

File tree

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ This will install `http-server-upload` globally so that it may be run from the c
2424
## Usage
2525

2626
```
27-
http-server-upload [options] [uploadRootPath]
27+
http-server-upload [arguments] [uploadRootPath]
2828
```
2929

3030
`[uploadRootPath]` defaults to the current working directory (`./`).
@@ -39,7 +39,7 @@ until the next free port is found. This can be disabled, see below.
3939
*Attention:* Already existing files will be overwritten on upload.
4040

4141

42-
### Options and environment variables
42+
### Arguments and environment variables
4343

4444
The optional configuration is done by command line arguments or environment variables.
4545
If both are used, the arguments have higher priority and the value from the
@@ -48,12 +48,13 @@ corresponding environment variable will be ignored.
4848
| Argument | Variable | Description | Default |
4949
|---|---|---|---|
5050
| `--port` | `PORT` | The port to use. | `8080` |
51-
| `--upload-dir` | `UPLOAD_DIR` | The directory where the files should be uploaded to. This overrides the `uploadRootPath` argument. | `uploadRootPath` argument or the current working directory |
51+
| `--upload-dir` | `UPLOAD_DIR` | The directory where the files should be uploaded to. This overrides the `uploadRootPath` argument. | `uploadRootPath` argument or the current working directory |
5252
| `--upload-tmp-dir` | `UPLOAD_TMP_DIR` | Temp directory for the file upload. | The upload directory. |
5353
| `--max-file-size` | `MAX_FILE_SIZE` | The maximum allowed file size for uploads in Megabyte. | `200` |
5454
| `--token` | `TOKEN` | An optional token which must be provided on upload. | Nothing |
5555
| `--path-regexp` | `PATH_REGEXP` | A regular expression to verify a given upload path. This should be set with care, because it may allow write access to outside the upload directory. | `/^[a-zA-Z0-9-_/]*$/` |
5656
| `--disable-auto-port` | `DISABLE_AUTO_PORT` | Disable automatic port increase if the port is nor available. | Not set. |
57+
| `--help`, `-h` | | Show some help text | |
5758

5859
Examples:
5960
```

http-server-upload.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,55 @@ console.log('HTTP Server Upload');
2929
// parse arguments
3030
let uploadDirSetFromArg = false;
3131
const myArgs = process.argv.slice(2);
32+
33+
// help requested?
34+
if (myArgs.includes('--help') || myArgs.includes('-h')) {
35+
console.log(`A Simple zero-configuration command-line http server for uploading files.
36+
37+
The optional configuration is done by command line arguments or environment variables.
38+
If both are used, the arguments have higher priority and the value from the corresponding environment variable will be ignored.
39+
40+
Usage:
41+
http-server-upload [arguments] [uploadRootPath]
42+
43+
Argument | Environmen variable
44+
Description [Default value]
45+
46+
--port | PORT
47+
The port to use. [8080]
48+
--upload-dir | UPLOAD_DIR
49+
The directory where the files should be uploaded to.
50+
This overrides the uploadRootPath argument.
51+
[uploadRootPath argument or the current working directory]
52+
--upload-tmp-dir | UPLOAD_TMP_DIR
53+
Temp directory for the file upload. [The upload directory]
54+
--max-file-size | MAX_FILE_SIZE
55+
The maximum allowed file size for uploads in Megabyte. [200]
56+
--token | TOKEN
57+
An optional token which must be provided on upload. [Nothing]
58+
--path-regexp | PATH_REGEXP
59+
A regular expression to verify a given upload path.
60+
This should be set with care, because it may allow write access
61+
to outside the upload directory. [/^[a-zA-Z0-9-_/]*$/]
62+
--disable-auto-port | DISABLE_AUTO_PORT
63+
Disable automatic port increase if the port is nor available. [Not set]
64+
--help or -h
65+
Show this help text.
66+
67+
Examples:
68+
69+
PORT=9000 UPLOAD_DIR=~/uploads/ UPLOAD_TMP_DIR=/tmp/ TOKEN=my-super-secret-token http-server-upload
70+
71+
http-server-upload --port=9000 --upload-dir="c:\\users\\peter\\Path With Whitespaces\\"
72+
73+
PORT=9000 http-server-upload --disable-auto-port ./
74+
75+
Additional information:
76+
https://github.com/crycode-de/http-server-upload
77+
`);
78+
process.exit(0);
79+
}
80+
3281
while (myArgs.length > 0) {
3382
const arg = myArgs.shift();
3483
if (arg.startsWith('--')) {

0 commit comments

Comments
 (0)