Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 373d1d1

Browse filesBrowse files
committed
made smaller main function
1 parent 0bc3f33 commit 373d1d1
Copy full SHA for 373d1d1

File tree

5 files changed

+25
-22
lines changed
Filter options

5 files changed

+25
-22
lines changed

‎args/cli_args.cpp

Copy file name to clipboardExpand all lines: args/cli_args.cpp
+10-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,15 @@
33
//
44

55
#include "cli_args.h"
6+
#include "../utils/string_formatting/string_coloring.h"
67
#include <string>
8+
#include <iostream>
9+
#include <vector>
10+
#include <filesystem>
11+
namespace fs = std::filesystem;
712

8-
std::string parse_args() {
9-
return "hello args";
10-
}
13+
std::string parse_args(int argc, char* argv[]) {
14+
std::cout << argc << std::endl;
15+
if (argc <= 1) return ".";
16+
return "/Users/willlane/dev/nat";
17+
}

‎args/cli_args.h

Copy file name to clipboardExpand all lines: args/cli_args.h
+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
#define NATCPP_CLI_ARGS_H
77
#include <string>
88

9-
std::string parse_args();
9+
std::string parse_args(int, char**);
1010

1111
#endif //NATCPP_CLI_ARGS_H

‎main.cpp

Copy file name to clipboardExpand all lines: main.cpp
+1-18
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,11 @@
22
// Created by Will Lane on 2/2/21.
33
//
44

5-
//#include <filesystem>
6-
//#include <vector>
7-
#include <iostream>
8-
#include <string>
95
#include "args/cli_args.h"
106
#include "utils/types.h"
11-
#include "utils/fs/handle_files.h"
12-
namespace fs = std::filesystem;
137

148
int main(int argc, char* argv[]) {
15-
auto args = parse_args();
16-
auto f = get_files(".");
17-
18-
auto dir = new Directory(".");
19-
for (File file : dir->get_paths()) {
20-
std::cout << file.get_perms() << ' ';
21-
std::cout << file.get_size() << ' ';
22-
std::cout << file.get_group() << ' ';
23-
std::cout << file.get_user() << ' ';
24-
std::cout << file.get_modified() << ' ';
25-
std::cout << file.get_path().path() << std::endl;
26-
}
9+
(new Directory(parse_args(argc, argv)))->show_ls();
2710

2811
return 0;
2912
}

‎utils/types.cpp

Copy file name to clipboardExpand all lines: utils/types.cpp
+12
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <pwd.h>
1515
#include <chrono>
1616
#include <sstream>
17+
#include <iostream>
1718
namespace fs = std::filesystem;
1819

1920
File :: File (
@@ -152,3 +153,14 @@ Directory :: Directory (const std::string& path) {
152153
std::vector<File> Directory :: get_paths() {
153154
return this->paths;
154155
}
156+
157+
void Directory :: show_ls() {
158+
for (File file : this->get_paths()) {
159+
std::cout << file.get_perms() << ' ';
160+
std::cout << file.get_size() << ' ';
161+
std::cout << file.get_group() << ' ';
162+
std::cout << file.get_user() << ' ';
163+
std::cout << file.get_modified() << ' ';
164+
std::cout << file.get_path().path() << std::endl;
165+
}
166+
}

‎utils/types.h

Copy file name to clipboardExpand all lines: utils/types.h
+1
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,6 @@ class Directory {
8080
~Directory() = default;
8181

8282
std::vector<File> get_paths();
83+
void show_ls();
8384
};
8485
#endif //NATCPP_TYPES_H

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.