1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright 2016 - 2019, Thomas Lauf, Paul Beckingham, Federico Hernandez.
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included
13 // in all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 // SOFTWARE.
22 //
23 // https://www.opensource.org/licenses/mit-license.php
24 //
25 ////////////////////////////////////////////////////////////////////////////////
26
27 #include <commands.h>
28 #include <Table.h>
29 #include <iostream>
30
31 ////////////////////////////////////////////////////////////////////////////////
32 // Enumerate all extensions.
CmdExtensions(Rules & rules,const Extensions & extensions)33 int CmdExtensions (
34 Rules& rules,
35 const Extensions& extensions)
36 {
37 Table t;
38 t.width (1024);
39 t.colorHeader (Color ("underline"));
40 t.add ("Extension", true);
41 t.add ("Status", true);
42
43 for (auto& ext : extensions.all ())
44 {
45 File program (ext);
46
47 // Show program name.
48 auto row = t.addRow ();
49 t.set (row, 0, program.name ());
50
51 // Show extension status.
52 std::string perms;
53 if (! program.readable ()) perms = "Not readable";
54 else if (! program.executable ()) perms = "No executable";
55 else perms = "Active";
56
57 if (program.is_link ()) perms += " (link)";
58
59 t.set (row, 1, perms);
60 }
61
62 Directory extDir (rules.get ("temp.db"));
63 extDir += "extensions";
64
65 std::cout << '\n'
66 << "Extensions located in:\n"
67 << " " << extDir._data << '\n'
68 << '\n'
69 << t.render ()
70 << '\n';
71 return 0;
72 }
73
74 ////////////////////////////////////////////////////////////////////////////////
75