-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding timeout options both CLI and .cigar.json #32
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e44ac97
Adding timeout options both CLI and .cigar.json
WyriHaximus 84e8539
Removed short hand (ct) for --connect-timeout via https://github.com/…
WyriHaximus 33c4181
Test response timeout .json config and CLI flags through stubs via ht…
WyriHaximus 56cba08
s is now short the connect-timeout
WyriHaximus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -18,7 +18,7 @@ use Brunty\Cigar\Outputter; | |
use Brunty\Cigar\Parser; | ||
use Brunty\Cigar\Result; | ||
|
||
$options = getopt('c:ia:u:jh:', ['version', 'help', 'quiet', 'config:', 'insecure', 'auth:', 'url:', 'json', 'header:']); | ||
$options = getopt('c:ia:u:jh:t:ct:', ['version', 'help', 'quiet', 'config:', 'insecure', 'auth:', 'url:', 'json', 'header:', 'timeout:', 'connect-timeout:']); | ||
|
||
if (isset($options['help'])) { | ||
$content = <<<HELP | ||
|
@@ -27,14 +27,16 @@ if (isset($options['help'])) { | |
cigar [options] | ||
|
||
\033[33mOptions:\033[0m | ||
\033[32m-c file.json, --config=file.json\033[0m Use the specified config file instead of the default .cigar.json file | ||
\033[32m-u URL, --url=URL\033[0m Base URL for checks, e.g. https://example.org/ | ||
\033[32m-i, --insecure\033[0m Allow invalid SSL certificates | ||
\033[32m-a, --auth\033[0m Authorization header "\074type\076 \074credentials\076" | ||
\033[32m-h, --header\033[0m Custom header "\074name\076: \074value\076" | ||
\033[32m-j, --json\033[0m Output JSON | ||
\033[32m --quiet\033[0m Do not output any message | ||
\033[32m --version\033[0m Print the version of Cigar | ||
\033[32m-c file.json, --config=file.json\033[0m Use the specified config file instead of the default .cigar.json file | ||
\033[32m-u URL, --url=URL\033[0m Base URL for checks, e.g. https://example.org/ | ||
\033[32m-i, --insecure\033[0m Allow invalid SSL certificates | ||
\033[32m-a, --auth\033[0m Authorization header "\074type\076 \074credentials\076" | ||
\033[32m-h, --header\033[0m Custom header "\074name\076: \074value\076" | ||
\033[32m-ct, --connect-timeout=TIMEOUT\033[0m Connect Timeout | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Help output will need changing with the change of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed the mention of |
||
\033[32m-t, --timeout=TIMEOUT\033[0m Response Timeout | ||
\033[32m-j, --json\033[0m Output JSON | ||
\033[32m --quiet\033[0m Do not output any message | ||
\033[32m --version\033[0m Print the version of Cigar | ||
|
||
Created by Matt Brunt | ||
E: [email protected] | ||
|
@@ -78,17 +80,19 @@ if ( ! file_exists($file)) { | |
exit(1); | ||
} | ||
|
||
$secure = ! (isset($options['i']) || isset($options['insecure'])); | ||
$authorization = $options['a'] ?? $options['auth'] ?? null; | ||
$headers = (array) ($options['h'] ?? $options['header'] ?? []); | ||
$connectTimeout = $options['ct'] ?? $options['connect-timeout'] ?? null; | ||
$timeout = $options['t'] ?? $options['timeout'] ?? null; | ||
|
||
try { | ||
$domains = (new Parser($baseUrl))->parse($file); | ||
$domains = (new Parser($baseUrl, $connectTimeout, $timeout))->parse($file); | ||
} catch (\Throwable $e) { | ||
$outputter->writeErrorLine('Unable to parse .cigar.json file'); | ||
exit(1); | ||
} | ||
|
||
$secure = ! (isset($options['i']) || isset($options['insecure'])); | ||
$authorization = $options['a'] ?? $options['auth'] ?? null; | ||
$headers = (array) ($options['h'] ?? $options['header'] ?? []); | ||
|
||
$results = (new AsyncChecker($secure, $authorization, $headers))->check($domains); | ||
$passedResults = array_filter($results, function (Result $result) { | ||
return $result->hasPassed(); | ||
|
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shortopts are for single-character options only, so
ct
won't work (we also already have ac
and at
option, so it'll produce results like this:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doh my bad, changed it 👍