Merge: Correct warn on noautoinit
[nit.git] / contrib / sort_downloads / src / sort_downloads.nit
index dfad69a..4cfc3a1 100755 (executable)
@@ -26,13 +26,18 @@ module sort_downloads
 import opts
 
 `{
-#include <errno.h>
+       #include <errno.h>
+       #include <string.h>
 `}
 
 # Local config
 # Modify these according to your needs. It is also possible to have alternates
 # using class refinment and a main calling to super.
 class Config
+       # Is it configured? Change to "true" when the configuration has been
+       # adapted to your needs and setup
+       var is_configured = false
+
        # Source directory where are the files to be sorted.
        var source_dir = "~/Downloads/"
 
@@ -58,11 +63,11 @@ redef class String
        end
 
        # Returns null on success
-       fun file_rename_to(dest: String): nullable String import String::to_cstring,
-       String::from_cstring, String as nullable `{
-               int res = rename(String_to_cstring(recv), String_to_cstring(dest));
+       fun file_rename_to(dest: String): nullable String import String.to_cstring,
+       NativeString.to_s, String.as nullable `{
+               int res = rename(String_to_cstring(self), String_to_cstring(dest));
                if (res == 0) return null_String();
-               return String_as_nullable(new_String_from_cstring(strerror(errno)));
+               return String_as_nullable(NativeString_to_s(strerror(errno)));
        `}
 
        # Replace `~` by the path to the home diretory
@@ -80,7 +85,7 @@ end
 class PatternWithDir
        super BM_Pattern
 
-       var dir: String
+       var dir: String is noinit
 
        init with_dir(motif, dir: String)
        do
@@ -188,6 +193,10 @@ class XySorter
 end
 
 var config = new Config
+if not config.is_configured then
+       print "Not configured, make sure you modify the script and set is_configured to true"
+       exit 1
+end
 var sorter = new XySorter
 
 # calculate cut off time using `elapsed_days` compared to now