@@ -66,7 +66,7 @@ handleDependency(
66
66
static std::string
67
67
getDependencyGitUrl (const std::string_view dep) {
68
68
if (dep.find (" ://" ) == std::string_view::npos) {
69
- // check if atleast in "user/repo" format
69
+ // Check if at least in "user/repo" format.
70
70
if (dep.find (' /' ) == std::string_view::npos) {
71
71
logger::error (" Invalid dependency: " + std::string (dep));
72
72
return " " ;
@@ -88,9 +88,9 @@ getDependencyName(const std::string_view dep) {
88
88
);
89
89
}
90
90
91
- // Remove trailing '.git' if it exists
91
+ // Remove trailing '.git' if it exists.
92
92
if (name.ends_with (" .git" )) {
93
- name = name.substr (0 , name.size () - 4 );
93
+ name = name.substr (0 , name.size () - " .git " sv. size () );
94
94
}
95
95
96
96
return name;
@@ -103,6 +103,9 @@ addDependencyToManifest(
103
103
std::string& rev, std::string& branch
104
104
) {
105
105
toml::value depData = toml::table{};
106
+ // Set the formatting for the dependency data table to be on a single line.
107
+ // e.g. dep = { git = "https://github.com/user/repo.git", tag = "v1.0.0" }
108
+ depData.as_table_fmt ().fmt = toml::table_format::oneline;
106
109
107
110
if (isSystemDependency) {
108
111
if (version.empty ()) {
@@ -124,8 +127,14 @@ addDependencyToManifest(
124
127
}
125
128
}
126
129
127
- auto data = toml::parse (getManifestPath ());
128
- auto & deps = toml::find<toml::table>(data, " dependencies" );
130
+ // Keep the order of the tables.
131
+ auto data = toml::parse<toml::ordered_type_config>(getManifestPath ());
132
+
133
+ // Check if the dependencies table exists, if not create it.
134
+ if (data[" dependencies" ].is_empty ()) {
135
+ data[" dependencies" ] = toml::table{};
136
+ }
137
+ auto & deps = data[" dependencies" ];
129
138
130
139
for (const auto & dep : newDeps) {
131
140
@@ -145,7 +154,7 @@ addDependencyToManifest(
145
154
}
146
155
147
156
std::ofstream ofs (getManifestPath ());
148
- ofs << toml::format ( data) ;
157
+ ofs << data;
149
158
150
159
logger::info (" Added" , " to the poac.toml" );
151
160
return EXIT_SUCCESS;
0 commit comments