1 /**
2  * Copyright: Copyright (c) 2011 Jacob Carlborg. All rights reserved.
3  * Authors: Jacob Carlborg
4  * Version: Initial created: May 31, 2011
5  * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
6  */
7 module dvm.commands.List;
8 
9 import std.stdio : writeln;
10 
11 import tango.io.vfs.FileFolder;
12 
13 import dvm.commands.Command;
14 import Path = dvm.io.Path;
15 
16 class List : Command
17 {
18     this (string name, string summary = "")
19     {
20         super(name, summary);
21     }
22 
23     this ()
24     {
25         super("list", "Show currently installed D compilers.");
26     }
27 
28     override void execute ()
29     {
30         auto errorMessage = "No installed D compilers";
31 
32         if (!Path.exists(options.path.compilers))
33         {
34             writeln(errorMessage);
35             return;
36         }
37 
38         scope folder = new FileFolder(options.path.compilers);
39 
40         if (folder.self.folders == 0)
41         {
42             writeln(errorMessage);
43             return;
44         }
45 
46         writeln("Installed D compilers:\n");
47 
48         foreach (file ; folder)
49             writeln(stripPath(file.toString));
50     }
51 
52     private string stripPath (string name)
53     {
54         return Path.parse(name).file;
55     }
56 }