]> git.armaanb.net Git - gen-shell.git/blob - src/diag.cpp
3b4e3a9cdc436db97144325df623333f1df95319
[gen-shell.git] / src / diag.cpp
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright 2006 - 2017, Paul Beckingham, Federico Hernandez, 2020 Armaan Bhojwani.
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 // http://www.opensource.org/licenses/mit-license.php
24 //
25 ////////////////////////////////////////////////////////////////////////////////
26
27 #include <cmake.h>
28 #include <commit.h>
29 #include <iostream>
30 #include <string>
31 #include <vector>
32 #include <cstring>
33 #include <stdlib.h>
34 #include <FS.h>
35 #include <Color.h>
36 #include <shared.h>
37 #include <format.h>
38
39 #ifdef HAVE_READLINE
40 #include <readline/readline.h>
41 #include <readline/history.h>
42 #endif
43
44 ////////////////////////////////////////////////////////////////////////////////
45 int cmdDiagnostics ()
46 {
47   Color bold ("bold");
48
49   std::cout << "\n"
50             << bold.colorize (PACKAGE_STRING)
51             << "\n"
52             << "   " << "Platform: " << osName ()
53             << "\n\n";
54
55   // Compiler.
56   std::cout << bold.colorize ("Compiler")
57             << "\n"
58 #ifdef __VERSION__
59             << "    " << "Version: "
60             << __VERSION__ << "\n"
61 #endif
62             << "       " << "Caps:"
63 #ifdef __STDC__
64             << " +stdc"
65 #endif
66 #ifdef __STDC_HOSTED__
67             << " +stdc_hosted"
68 #endif
69 #ifdef __STDC_VERSION__
70             << " +" << __STDC_VERSION__
71 #endif
72 #ifdef _POSIX_VERSION
73             << " +" << _POSIX_VERSION
74 #endif
75 #ifdef _POSIX2_C_VERSION
76             << " +" << _POSIX2_C_VERSION
77 #endif
78 #ifdef _ILP32
79             << " +ILP32"
80 #endif
81 #ifdef _LP64
82             << " +LP64"
83 #endif
84             << " +c"      << 8 * sizeof (char)
85             << " +i"      << 8 * sizeof (int)
86             << " +l"      << 8 * sizeof (long)
87             << " +vp"     << 8 * sizeof (void*)
88             << " +time_t" << 8 * sizeof (time_t)
89             << "\n";
90
91   // Compiler compliance level.
92   std::cout << " Compliance: "
93             << cppCompliance ()
94             << "\n\n";
95
96   std::cout << bold.colorize ("Build Features")
97             << "\n"
98
99   // Build date.
100             << "      " << "Built: " << __DATE__ << " " << __TIME__ << "\n"
101 #ifdef HAVE_COMMIT
102             << "     " << "Commit: " << COMMIT << "\n"
103 #endif
104             << "      CMake: " << CMAKE_VERSION << "\n";
105
106   std::cout << "libreadline: "
107 #ifdef HAVE_READLINE
108 #ifdef RL_VERSION_MAJOR
109             << RL_VERSION_MAJOR << "." << RL_VERSION_MINOR
110 #elif defined RL_READLINE_VERSION
111             << "0x" << std::hex << RL_READLINE_VERSION
112 #endif
113 #else
114             << "n/a"
115 #endif
116             << "\n";
117
118   std::cout << " Build type: "
119 #ifdef CMAKE_BUILD_TYPE
120             << CMAKE_BUILD_TYPE
121 #else
122             << "-"
123 #endif
124             << "\n\n";
125
126   std::cout << bold.colorize ("Configuration")
127             << "\n";
128
129   auto env = getenv ("TASKRC");
130   std::cout << "     TASKRC: "
131             << (env ? env : "")
132             << "\n";
133
134   env = getenv ("TASKDATA");
135   std::cout << "   TASKDATA: "
136             << (env ? env : "")
137             << "\n";
138
139   // Taskwarrior version + location
140   std::string path (getenv ("PATH"));
141   std::cout << "       PATH: " << path << "\n";
142
143   for (const auto& i : split (path, ':'))
144   {
145     File task (i + "/task");
146     if (task.exists ())
147     {
148       std::string input;
149       std::string output;
150       execute ("task", {"--version"}, input, output);
151
152       std::cout << "Taskwarrior: "
153                 << i
154                 << "/task "
155                 << output; // Still has \n
156     }
157   }
158
159   std::cout << "\n";
160   return 0;
161 }
162
163 ////////////////////////////////////////////////////////////////////////////////