Browse Source

is key-value in toml config; add command line argument

221V 1 month ago
parent
commit
746b5b687e
2 changed files with 18 additions and 8 deletions
  1. 6 1
      Makefile
  2. 12 7
      source/dopp.d

+ 6 - 1
Makefile

@@ -3,7 +3,12 @@ d:
 	dub build --compiler ldc2 --build release --force
 	dub build --compiler ldc2 --build release --force
 
 
 t:
 t:
+	./dopp -t
+
+dt: d t
+
+ut:
 	dub test
 	dub test
 
 
 default: d
 default: d
-.PHONY: d t
+.PHONY: d dt t ut

+ 12 - 7
source/dopp.d

@@ -1,5 +1,5 @@
 
 
-//import toml;
+import toml;
 
 
 public{
 public{
   import std.stdio : writeln;
   import std.stdio : writeln;
@@ -16,7 +16,7 @@ public{
 //import dopp_parser : parse;
 //import dopp_parser : parse;
 
 
 
 
-//TOMLDocument toml_s;
+TOMLDocument toml_s;
 
 
 
 
 export enum TokenType{
 export enum TokenType{
@@ -44,6 +44,7 @@ export struct Token{
 
 
 
 
 
 
+// ./dopp -t == shortened for test (onto single .de -> .d module)
 // ./dopp -d "/test" -o "/test2" == input dir path + output dir path (default output dir = input dir)
 // ./dopp -d "/test" -o "/test2" == input dir path + output dir path (default output dir = input dir)
 // ./dopp -f test.de -o test.d == input file name + output file name (default output file name = input file name [but .d instead .de] )
 // ./dopp -f test.de -o test.d == input file name + output file name (default output file name = input file name [but .d instead .de] )
 // ./dopp -f "/test/test.de" -o "/result/test.d" == input file path + output file path (default output file name and path = input file name and path [but .d instead .de] )
 // ./dopp -f "/test/test.de" -o "/result/test.d" == input file path + output file path (default output file name and path = input file name and path [but .d instead .de] )
@@ -53,8 +54,8 @@ bool is_valid_argv(ref string[] argv){
   if(num != 1 && num != 2 && num != 4){
   if(num != 1 && num != 2 && num != 4){
     return false;
     return false;
   
   
-  }else if(num == 1){ // one argument only (just filename or /path/filename) == shortened ./dopp -f test.de = ./dopp test.de
-    if(argv[0].length >= 4 && argv[0][$-3 .. $] == ".de"){
+  }else if(num == 1){ // one argument only (just filename or /path/filename) == shortened ./dopp -f test.de = ./dopp test.de; or -t == shortened for test (onto single .de -> .d module)
+    if( (argv[0] == "-t") || (argv[0].length >= 4 && argv[0][$-3 .. $] == ".de") ){
       return true;
       return true;
     }else{
     }else{
       return false;
       return false;
@@ -110,11 +111,13 @@ bool is_valid_argv(ref string[] argv){
 
 
 //void main(string[] argv){
 //void main(string[] argv){
 int main(string[] argv){
 int main(string[] argv){
-  /*
+  
   toml_s = parseTOML(cast(string)read("dopp.toml"));
   toml_s = parseTOML(cast(string)read("dopp.toml"));
   writeln("indent_matter: ", toml_s["indent_matter"]); // 4
   writeln("indent_matter: ", toml_s["indent_matter"]); // 4
-  writeln("xyz: ", toml_s["xyz"]); // Address boundary error
-  */
+  //writeln("xyz: ", toml_s["xyz"]); // Address boundary error || Segmentation fault (core dumped)
+  writeln("indent_matter in: ", "indent_matter" in toml_s);
+  writeln("xyz in: ", "xyz" in toml_s);
+  // todo function - config and default values
   
   
   /*
   /*
   int i = 0;
   int i = 0;
@@ -147,6 +150,7 @@ int main(string[] argv){
 unittest{
 unittest{
   assert( is_valid_argv([]) == false );
   assert( is_valid_argv([]) == false );
   assert( is_valid_argv([""]) == false );
   assert( is_valid_argv([""]) == false );
+  assert( is_valid_argv(["-t"]) == true );
   assert( is_valid_argv(["-d"]) == false );
   assert( is_valid_argv(["-d"]) == false );
   assert( is_valid_argv(["-d", ""]) == false );
   assert( is_valid_argv(["-d", ""]) == false );
   assert( is_valid_argv(["-d", "/test"]) == true );
   assert( is_valid_argv(["-d", "/test"]) == true );
@@ -160,6 +164,7 @@ unittest{
   assert( is_valid_argv(["-f", "test.de", "-o", "test.txt"]) == false );
   assert( is_valid_argv(["-f", "test.de", "-o", "test.txt"]) == false );
 }
 }
 
 
+// ./dopp -t == shortened for test (onto single .de -> .d module)
 // ./dopp -d "/test" -o "/test2" == input dir path + output dir path (default output dir = input dir)
 // ./dopp -d "/test" -o "/test2" == input dir path + output dir path (default output dir = input dir)
 // ./dopp -f test.de -o test.d == input file name + output file name (default output file name = input file name [but .d instead .de] )
 // ./dopp -f test.de -o test.d == input file name + output file name (default output file name = input file name [but .d instead .de] )
 // ./dopp -f "/test/test.de" -o "/result/test.d" == input file path + output file path (default output file name and path = input file name and path [but .d instead .de] )
 // ./dopp -f "/test/test.de" -o "/result/test.d" == input file path + output file path (default output file name and path = input file name and path [but .d instead .de] )