-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
115 lines (112 loc) · 3.63 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
const yargs = require('yargs');
const argv = yargs
.option('image', {
alias: 'i',
description: 'Path to the image you want to print (e.g ~/folder/image.png)',
type: 'string',
})
.option('ipp', {
alias: 'p',
description: 'Run in IPP/Postscript mode, exposes a generic PS printer you can use from any app',
type: 'boolean',
})
.option('http', {
description: 'Run in HTTP mode, exposes API for printing',
type: 'boolean',
})
.option('sms', {
description: 'Run in SMS mode, polls printkitty-sms-service for SMS to print, provide the base url for the service',
type: 'string',
})
.option('smsuser', {
description: 'username for the printkitty-sms-service',
type: 'string',
})
.option('smspassword', {
description: 'password for the printkitty-sms-service',
type: 'string',
})
.option('smspoll', {
description: 'Frequency in seconds to poll for new SMS messages',
type: 'integer',
default: 10
})
.option('ippname', {
alias: 'q',
description: 'Name to broadcast when in IPP/PS Mode (e.g "kitty")',
type: 'string',
default: 'cat printer uwu'
})
.option('text', {
alias: 't',
description: 'Text you want to print in quotes, default font is Arial, 20px (e.g "hello world")',
type: 'string',
})
.option('font', {
alias: 'f',
description: 'The font to use in quotes, this must be provided as it exists on your machine (e.g "Comic Sans MS")',
type: 'string',
default: 'arial'
})
.option('fontsize', {
alias: 's',
description: 'The font size to use, in pixels high (e.g 16)',
type: 'integer',
default: 20
})
.option('getinfo', {
alias: 'g',
description: 'Returns printer info in hex',
type: 'boolean',
})
.option('getstatus', {
alias: 'u',
description: 'Returns printer info in hex',
type: 'boolean',
})
.option('eject', {
alias: 'e',
description: 'Ejects a number of lines of paper (e.g 50)',
type: 'integer',
})
.option('retract', {
alias: 'r',
description: 'Retracts the paper by a number of lines (e.g 50)',
type: 'integer',
})
.option('devicename', {
alias: 'n',
description: 'The name of your cat printer (e.g GT01)',
type: 'string',
default: 'GB01'
})
.option('timeout', {
alias: 'o',
description: 'Time in seconds to wait before aborting, when connecting to the printer (e.g 10)',
type: 'integer',
default: 5
})
.option('loglevel', {
alias: 'l',
description: 'Logging level to use, values are trace, debug, info, warn, error, fatal. Defaults to error',
type: 'string',
default: 'info'
})
.choices('loglevel', ['trace', 'debug', 'info', 'warn', 'error', 'fatal'])
.help()
.alias('help', 'h')
.epilogue('For more information, check out the project repository at https://github.com/mickwheelz/printkitty.js ~nyaa')
.env('PRINTKITTY')
.demandOption('devicename', 'You must specify a device')
.wrap(yargs.terminalWidth())
.check((argv) => {
if (!argv.ipp & !argv.image && !argv.text && !argv.eject && !argv.retract && !argv.getinfo && !argv.getstatus && !argv.http && !argv.sms ) {
throw new Error("Oh Noes! You must specify a task to perform, e.g --image <image>, --eject 20")
} else {
return true
}
})
.argv;
module.exports = {
args: argv
};