Switch from libsoup to libcurl, add login and my information support
[beifahrer] / src / beifahrer-cli.vala
index 31bf3d9..aefa372 100644 (file)
@@ -72,17 +72,36 @@ async void get_details (string href) {
        loop.quit ();
 }
 
+void usage () {
+       print ("usage: beifahrer-cli <city_from> <city_to> [date]\n");
+       print ("or:    beifahrer-cli details <lift_url>\n");
+       print ("or:    beifahrer-cli login <username> <password>\n");
+       print ("or:    beifahrer-cli login <cookie>\n");
+}
+
 static int main (string[] args) {
        loop = new MainLoop (null);
 
        if (args.length < 3) {
-               print ("usage: beifahrer-cli <city_from> <city_to> [date]\n");
-               print ("or:    beifahrer-cli details <lift_url>\n");
+               usage ();
                return 1;
        }
 
+       Curl.global_init (Curl.GLOBAL_DEFAULT);
+
        adac = new AdacMitfahrclub ();
 
+       if (args[1] == "login") {
+               if (args.length > 3) {
+                       adac.login (args[2], args[3]);
+               } else {
+                       adac.set_cookie (args[2]);
+                       adac.login (null, null);
+               }
+               loop.run ();
+               return 0;
+       }
+
        if (args[1] == "details") {
                get_details.begin (args[2]);
 
@@ -104,5 +123,8 @@ static int main (string[] args) {
        get_lifts.begin (city_from, city_to, date);
 
        loop.run ();
+
+       Curl.global_cleanup ();
+
        return 0;
 }