Skip to content

Commit

Permalink
[Net] Add in an example curl-alike program which uses Rosella.Net to …
Browse files Browse the repository at this point in the history
…duplicate some functionality from the popular curl program.
  • Loading branch information
Whiteknight committed Aug 25, 2012
1 parent 2202d74 commit 49ffe64
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions examples/curl.winxed
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,56 @@
$include "Rosella/Core.winxed";
$include "Rosella/CommandLine.winxed";
$include "Rosella/Net.winxed";

function curl_main(var args)
{
string url = args["url"];
string http_mode = args["-X"];
if (http_mode == null || http_mode == "")
http_mode = "GET";
int verbose = args["-v"];

var ua = new Rosella.Net.UserAgent.SimpleHttp();
if (verbose)
ua.set_dbg_handle(getstdout());
var response;
switch (http_mode) {
//case "HEAD":
case "GET":
case "DELETE":
response = ua.request(http_mode, url);
if (!verbose)
say(response.content);
break;
case "PUT":
case "POST":
var post_args = args["-p"];
// TODO: Get a list of files
response = ua.request("POST", url, post_args, null);
if (!verbose)
say(response.content);
break;
default:
Rosella.Error.error("Unknown http mode '%s'", http_mode);
}
}

function main[main](var args)
{
using curl_main;
var p = new Rosella.CommandLine.Program(args.shift());
p.default_mode().set_function(curl_main)
.require_positional("url", 0)
.optional_args({
"-v" : "f",
"-X" : "s",
"-p" : "h"
});
p.add_mode("help").set_flag("--help").set_function(usage_and_exit);
p.on_error(usage_and_exit);
p.run(args);
}

function usage_and_exit(var args)
{
}

0 comments on commit 49ffe64

Please sign in to comment.