blob: 8410cbabec80c059177d4a13158e6216155c189c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#include "clicommanddir.h"
#include <QDir>
void CliCommandDir::execute()
{
QDir dir;
QFileInfoList entries;
if (syntax.isArgumentSet(DIR_OR_FILE))
{
QString filter = getFilterAndFixDir(dir, syntax.getArgument(DIR_OR_FILE));
entries = dir.entryInfoList({filter}, QDir::AllEntries|QDir::NoDotAndDotDot, QDir::DirsFirst|QDir::LocaleAware|QDir::Name);
}
else
entries = dir.entryInfoList(QDir::AllEntries|QDir::NoDotAndDotDot, QDir::DirsFirst|QDir::LocaleAware|QDir::Name);
QString name;
for (const QFileInfo& entry : entries)
{
name = entry.fileName();
if (entry.isDir())
name += "/";
if (dir != QDir::current())
name.prepend(dir.path()+"/");
println(name);
}
}
QString CliCommandDir::shortHelp() const
{
return tr("lists directories and files in current working directory");
}
QString CliCommandDir::fullHelp() const
{
return tr(
"This is very similar to 'dir' command known from Windows and 'ls' command from Unix systems.\n"
"\n"
"You can pass <pattern> with wildcard characters to filter output."
);
}
void CliCommandDir::defineSyntax()
{
syntax.setName("dir");
syntax.addAlias("ls");
syntax.addArgument(DIR_OR_FILE, tr("pattern"), false);
}
|