You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
stripIndents`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:
100
-
101
-
- Scope must be "repo" or "org" ${badScope ? colors.red('(bad!)') : colors.green('(ok)')}
102
-
103
-
- The time filter must either be 7, 30 or 90 ${badTime ? colors.red('(bad!)') : colors.green('(ok)')}
104
-
105
-
${scope==='repo' ? `- Repository name using --repo when scope is "repo" ${badRepo ? colors.red('(bad!)') : colors.green('(ok)')}` : ''}
106
-
107
-
${badFlags ? `- The \`--json\` and \`--markdown\` flags can not be used at the same time ${badFlags ? colors.red('(bad!)') : colors.green('(ok)')}` : ''}
108
-
109
-
${badFile ? `- The \`--file\` flag is only valid when using \`--json\` or \`--markdown\` ${badFile ? colors.red('(bad!)') : colors.green('(ok)')}` : ''}
110
-
`
111
-
.split('\n')
112
-
.filter(s=>!!s.trim())
113
-
.join('\n')
114
-
)
90
+
constwasBadInput=handleBadInput(
91
+
{
92
+
test: scope==='org'||scope==='repo',
93
+
message: 'Scope must be "repo" or "org"',
94
+
pass: 'ok',
95
+
fail: 'bad'
96
+
},
97
+
{
98
+
test: time===7||time===30||time===90,
99
+
message: 'The time filter must either be 7, 30 or 90',
100
+
pass: 'ok',
101
+
fail: 'bad'
102
+
},
103
+
{
104
+
nook: true,
105
+
test: scope==='org'||repo,
106
+
message: 'When scope=repo, repo name should be set through --repo',
107
+
pass: 'ok',
108
+
fail: 'missing'
109
+
},
110
+
{
111
+
nook: true,
112
+
test: file==='-'||json||markdown,
113
+
message:
114
+
'The `--file` flag is only valid when using `--json` or `--markdown`',
115
+
pass: 'ok',
116
+
fail: 'bad'
117
+
},
118
+
{
119
+
nook: true,
120
+
test: !json||!markdown,
121
+
message:
122
+
'The `--json` and `--markdown` flags can not be used at the same time',
123
+
pass: 'ok',
124
+
fail: 'bad'
125
+
},
126
+
{
127
+
nook: true,
128
+
test: apiToken,
129
+
message:
130
+
'You need to be logged in to use this command. See `socket login`.',
131
+
pass: 'ok',
132
+
fail: 'missing API token'
133
+
}
134
+
)
135
+
if(wasBadInput){
115
136
return
116
137
}
117
138
@@ -120,6 +141,9 @@ async function run(
120
141
return
121
142
}
122
143
144
+
assert(assertScope(scope))
145
+
assert(assertTime(time))
146
+
123
147
returnawaitdisplayAnalytics({
124
148
scope,
125
149
time,
@@ -128,3 +152,11 @@ async function run(
128
152
filePath: String(file||'')
129
153
})
130
154
}
155
+
156
+
functionassertScope(scope: unknown): scope is 'org'|'repo'{
157
+
returnscope==='org'||scope==='repo'
158
+
}
159
+
160
+
functionassertTime(time: unknown): time is 7|30|90{
0 commit comments