Skip to content

Commit 21ccf4e

Browse files
committed
Improves help documentation
1 parent 49e79ec commit 21ccf4e

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/https/Program.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,14 @@ static IEnumerable<Content> ParseContents(IEnumerable<string> args)
129129
}
130130
}
131131

132-
static void Help()
132+
void Help()
133133
{
134-
Console.WriteLine("https [method] [uri] [options] [content]");
134+
var stream = _stdout();
135+
var writer = new StreamWriter(stream) { AutoFlush = true };
136+
writer.WriteLine("https [method] [uri] [options] [content]");
137+
writer.WriteLine("For example https put httpbin.org/put hello=world");
138+
writer.WriteLine("");
139+
writer.Flush();
135140
}
136141

137142
static void AddHeaders(HttpRequestMessage request, IEnumerable<Content> contents)
@@ -173,7 +178,19 @@ public async Task<int> RunAsync(string[] args)
173178
return 1;
174179
}
175180

176-
if (!Command.TryParse(args[0], args[1], out var command))
181+
var command = default(Command);
182+
if (args.Length > 1)
183+
{
184+
if (!Command.TryParse(args[0], args[1], out command))
185+
{
186+
if (!Command.TryParse(args[0], out command))
187+
{
188+
Help();
189+
return 1;
190+
}
191+
}
192+
}
193+
else if (!Command.TryParse(args[0], out command))
177194
{
178195
Help();
179196
return 1;
@@ -430,7 +447,7 @@ struct Command
430447
}
431448

432449
static bool StartsWithHttp(string s) =>
433-
s.Length > 4 && s[0] == 'h' && s[1] == 't' && s[2] == 't' && s[3] == 'p';
450+
s.Length > 6 && s[0] == 'h' && s[1] == 't' && s[2] == 't' && s[3] == 'p' && (s[4] == ':' || (s[4] == 's' && s[5] == ':'));
434451

435452
static bool TryParseUri(string s, out Uri uri)
436453
{

0 commit comments

Comments
 (0)