Skip to content

Commit a0359ce

Browse files
committed
Convert to command line interface
1 parent e9c6ba3 commit a0359ce

File tree

3 files changed

+14
-53
lines changed

3 files changed

+14
-53
lines changed

app/Console/Commands/CurlCommand.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,28 @@
22

33
namespace App\Console\Commands;
44

5+
use App\Support\HttpCall;
56
use Illuminate\Console\Command;
67

78
class CurlCommand extends Command
89
{
9-
protected $signature = 'curl {--X|request=GET} {--H|header=*} {--d|data=*} {--F|form=*} {--digest} {--basic} {--connect-timeout=} {--retry=} {--s|silent} {--u|user=} {url}';
10+
protected $signature = 'shift:curl {--X|request=GET} {--H|header=*} {--d|data=*} {--F|form=*} {--digest} {--basic} {--connect-timeout=} {--retry=} {--s|silent} {--u|user=} {url}';
1011

11-
protected $description = 'Parse UNIX curl command';
12+
protected $description = 'Convert a UNIX curl request to an HTTP Client request';
1213

1314
public function handle()
1415
{
15-
$json = [
16+
$request = \App\Models\Request::create($this->gatherOptions());
17+
$code = HttpCall::format($request);
18+
19+
$this->line($code);
20+
21+
return 0;
22+
}
23+
24+
private function gatherOptions()
25+
{
26+
return [
1627
'method' => $this->option('request'),
1728
'url' => $this->argument('url'),
1829
'headers' => $this->option('header'),
@@ -26,9 +37,5 @@ public function handle()
2637
'user' => $this->option('user'),
2738
// TODO: map more options...
2839
];
29-
30-
$this->line(json_encode($json));
31-
32-
return 0;
3340
}
3441
}

app/Http/Controllers/ConverterController.php

Lines changed: 0 additions & 42 deletions
This file was deleted.

routes/web.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
11
<?php
2-
3-
use Illuminate\Support\Facades\Route;
4-
5-
Route::resource('/', \App\Http\Controllers\ConverterController::class)->only('create', 'store');

0 commit comments

Comments
 (0)