Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit f88f534

Browse files
authored
✨ Introduce class Context (#98)
* Aggregate delimiter. * Introduce Context * Remove unused variable.
1 parent 6f93979 commit f88f534

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

src/fetch.cpp

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* @file
33
*/
44
#include "fetch.h"
5+
string Context::PACKAGE_DELIM = "; "s;
56

67
/**
78
* @returns gets the username
@@ -352,60 +353,66 @@ vector<string> getGPU()
352353
string getPackages()
353354
{
354355
auto red = Crayon{}.red();
355-
string pkg = "";
356+
vector<string> pkgs;
356357
if (Path::of("/bin/dpkg"s).isExecutable())
357358
{
358359
auto c = Command::exec("dpkg -l"s);
359-
pkg += to_string(c.getOutputLines()) + red.text(" dpkg; ");
360+
pkgs.push_back(to_string(c.getOutputLines()) + red.text(" dpkg"s));
360361
}
361362
if (Path::of("/bin/snap"s).isExecutable())
362363
{
363364
auto c = Command::exec("snap list"s);
364-
pkg += to_string(c.getOutputLines()) + red.text(" snap; ");
365+
pkgs.push_back(to_string(c.getOutputLines()) + red.text(" snap"s));
365366
}
366367
if (Path::of("/bin/pacman"s).isExecutable())
367368
{
368369
auto c = Command::exec("pacman -Q"s);
369-
pkg += to_string(c.getOutputLines()) + red.text(" pacman; ");
370+
pkgs.push_back(to_string(c.getOutputLines()) + red.text(" pacman"s));
370371
}
371372
if (Path::of("/bin/flatpak"s).isExecutable())
372373
{
373374
auto c = Command::exec("flatpak list"s);
374-
pkg += to_string(c.getOutputLines()) + red.text(" flatpak; ");
375+
pkgs.push_back(to_string(c.getOutputLines()) + red.text(" flatpak"s));
375376
}
376377
if (Path::of("/var/lib/rpm"s).isExecutable())
377378
{
378379
auto c = Command::exec("rpm -qa"s);
379-
pkg += to_string(c.getOutputLines()) + red.text(" rpm; ");
380+
pkgs.push_back(to_string(c.getOutputLines()) + red.text(" rpm"s));
380381
}
381382
if (Path::of("/bin/npm"s).isExecutable())
382383
{
383384
auto c = Command::exec("npm list"s);
384-
pkg += to_string(c.getOutputLines()) + red.text(" npm; ");
385+
pkgs.push_back(to_string(c.getOutputLines()) + red.text(" npm"s));
385386
}
386387
if (Path::of("/bin/emerge"s).isExecutable()) // gentoo
387388
{
388-
pkg += "not supported"s + red.text(" portage; ");
389+
pkgs.push_back("not supported"s + red.text(" portage"s));
389390
}
390391
if (Path::of("/bin/xbps-install"s).isExecutable()) // void linux
391392
{
392393
auto c = Command::exec("flatpak list"s);
393-
pkg += to_string(c.getOutputLines()) + red.text(" xbps; ");
394+
pkgs.push_back(to_string(c.getOutputLines()) + red.text(" xbps"s));
394395
}
395396
if (Path::of("/bin/dnf"s).isExecutable()) // fedora
396397
{
397398
auto c = Command::exec("dnf list installed"s);
398-
pkg += to_string(c.getOutputLines()) + red.text(" dnf; ");
399+
pkgs.push_back(to_string(c.getOutputLines()) + red.text(" dnf"s));
399400
}
400401
if (Path::of("/bin/zypper"s).isExecutable()) // opensuse
401402
{
402403
auto c = Command::exec("zypper se --installed-only"s);
403-
pkg += to_string(c.getOutputLines()) + red.text(" zypper; ");
404+
pkgs.push_back(to_string(c.getOutputLines()) + red.text(" zypper"s));
404405
}
405406
if (Path::of("/home/linuxbrew/.linuxbrew/bin/brew"s).isExecutable())
406407
{
407408
auto c = Command::exec("brew list | { tr '' '\n'; }"s);
408-
pkg += to_string(c.getOutputLines()) + red.text(" brew; ");
409+
pkgs.push_back(to_string(c.getOutputLines()) + red.text(" brew"s));
410+
}
411+
412+
auto pkg = ""s;
413+
for (auto p : pkgs)
414+
{
415+
pkg += p + Context::PACKAGE_DELIM;
409416
}
410417

411418
return pkg;

src/fetch.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,12 @@ class Crayon
318318
}
319319
};
320320

321+
class Context
322+
{
323+
public:
324+
static string PACKAGE_DELIM;
325+
};
326+
321327
enum class Mode
322328
{
323329
NORMAL,

0 commit comments

Comments
 (0)