This repository has been archived by the owner on Feb 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sprig.cpp
233 lines (218 loc) · 8.21 KB
/
sprig.cpp
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include "json.hpp"
#include <cstdio>
using namespace std;
using json = nlohmann::json;
int main(int argc, char** argv){
string bob[6];
for (int i = 0; i < argc; ++i) {
bob[i]=argv[i];
}
cout << "Welcome! Use sprig help for more info."<<endl;
char grab[]="pick";
char info[]="info";
char build[]="build";
char grow[]="grow";
if (bob[1]==grab) {
string cmd;
string cmdpart0="curl ";
string cmdpart1="https://sprigrsmy.000webhostapp.com/";
string cmdpart2=bob[2];
string cmdpart3=".rsmy > ";
string cmdpart4=bob[2];
string cmdpart5=".rsmy";
string cmd1=cmdpart0+cmdpart1+cmdpart2+cmdpart3+cmdpart4+cmdpart5;
const int length = cmd1.length();
char* char_array = new char[length + 1];
strcpy(char_array, cmd1.c_str());
system(char_array);
string cmdpart01="curl ";
string cmdpart11="https://sprigrsmy.000webhostapp.com/";
string cmdpart21=bob[2];
string cmdpart31=".json > ";
string cmdpart41=bob[2];
string cmdpart51=".json";
string cmd11=cmdpart01+cmdpart11+cmdpart21+cmdpart31+cmdpart41+cmdpart51;
const int length1 = cmd1.length();
char* char_array1 = new char[length1 + 1];
strcpy(char_array1, cmd11.c_str());
system(char_array1);
}
if (bob[1]==info) {
ifstream f(bob[2]+".json");
json data = json::parse(f);
cout << "Name of Package - " << data["name"] <<endl;
cout << "Description - " << data["desc"]<<endl;
cout << "Version - " << data["version"]<<endl;
}
if (bob[1]==build) {
bool sprigexist;
string cmd;
string cmdpart0="curl ";
string cmdpart1="https://sprigrsmy.000webhostapp.com/";
string cmdpart2=bob[2];
string cmdpart3=".rsmy > ";
string cmdpart4=bob[2];
string cmdpart5=".rsmy";
string cmd1=cmdpart0+cmdpart1+cmdpart2+cmdpart3+cmdpart4+cmdpart5;
const int length = cmd1.length();
char* char_array = new char[length + 1];
strcpy(char_array, cmd1.c_str());
system(char_array);
string mytext;
std::ifstream ifs(bob[2]+".rsmy");
std::string content( (std::istreambuf_iterator<char>(ifs) ),
(std::istreambuf_iterator<char>() ) );
char lll = content[0];
char doc='<';
if (lll!=doc) {
sprigexist=true;
}
else {
sprigexist=false;
cout << "Oh No! The Package "<<bob[2]<<" already exists! Try using another name."<<endl;
exit(0);
}
if (sprigexist==false) {
cout << "Uploading your files to the server..."<<endl;
string cmd;
string cmdpart0="curl -T";
string cmdpart1=bob[3];
string cmdpart2=" -u b:b ftp://files.000webhost.com/public_html/";
string cmdpart3=bob[2];
string cmdpart4=".rsmy";
string cmd1=cmdpart0+cmdpart1+cmdpart2+cmdpart3+cmdpart4;
const int length = cmd1.length();
char* char_array = new char[length + 1];
strcpy(char_array, cmd1.c_str());
system(char_array);
string cmdpart01="curl -T";
string cmdpart11=bob[4];
string cmdpart21=" -u b:b ftp://files.000webhost.com/public_html/";
string cmdpart31=bob[2];
string cmdpart41=".json";
string cmd11=cmdpart01+cmdpart11+cmdpart21+cmdpart31+cmdpart41;
const int length1 = cmd1.length();
char* char_array1 = new char[length1 + 1];
strcpy(char_array1, cmd11.c_str());
system(char_array1);
string cmdpart011="curl -T ";
string cmdpart111=bob[5];
string cmdpart211=" -u b:b ftp://files.000webhost.com/public_html/";
string cmdpart311=bob[2];
string cmdpart411=".passwd";
string cmd111=cmdpart011+cmdpart111+cmdpart211+cmdpart311+cmdpart411;
const int length11 = cmd111.length();
char* char_array11 = new char[length1 + 1];
strcpy(char_array11, cmd111.c_str());
system(char_array11);
cout << "Done! You created the sprig "<<bob[2]<<endl;
}
}
if (bob[1]==grow) {
string cmd;
string cmdpart0="curl ";
string cmdpart1="https://sprigrsmy.000webhostapp.com/";
string cmd1=cmdpart0+cmdpart1+cmdpart2+cmdpart3+cmdpart4+cmdpart5;
const int length = cmd1.length();
char* char_array = new char[length + 1];
strcpy(char_array, cmd1.c_str());
system(char_array);
string file="";
// std::ifstream ifs(bob[2]+".passwd");
// std::string content( (std::istreambuf_iterator<char>(ifs) ),
// (std::istreambuf_iterator<char>() ) );
fstream my_file;
string bob3;
my_file.open(bob[2]+".passwd", ios::in);
if (!my_file) {
cout << "No such file";
}
else {
char ch;
while (1) {
my_file >> ch;
if (my_file.eof())
break;
bob3=bob3+ch;
}
}
my_file.close();
string cmddd;
string cmdddpart0="del ";
string cmdddpart1=bob[2];
string cmdddpart2=".passwd";
cmddd=cmdddpart0+cmdddpart1+cmdddpart2;
const int length1dd = cmddd.length();
char* char_array1dd = new char[length1dd + 1];
strcpy(char_array1dd, cmddd.c_str());
system(char_array1dd);
if (bob3==bob[5]) {
cout << "Uploading your files to the server..."<<endl;
string cmd;
string cmdpart0="curl -T";
string cmdpart1=bob[3];
string cmdpart2=" -u b:b ftp://files.000webhost.com/public_html/";
string cmdpart3=bob[2];
string cmdpart4=".rsmy";
string cmd1=cmdpart0+cmdpart1+cmdpart2+cmdpart3+cmdpart4;
const int length = cmd1.length();
char* char_array = new char[length + 1];
strcpy(char_array, cmd1.c_str());
system(char_array);
string cmdpart01="curl -T";
string cmdpart11=bob[4];
string cmdpart21=" -u b:b ftp://files.000webhost.com/public_html/";
string cmdpart31=bob[2];
string cmdpart41=".json";
string cmd11=cmdpart01+cmdpart11+cmdpart21+cmdpart31+cmdpart41;
const int length1 = cmd1.length();
char* char_array1 = new char[length1 + 1];
strcpy(char_array1, cmd11.c_str());
system(char_array1);
cout << "Done! Your code was pushed to sprig "<<bob[2]<<endl;
}
}
char help[]="help";
if (bob[1]==help) {
cout << "_ " <<endl;
cout << " (_) "<<endl;
cout << " ___ _ __ _ __ _ __ _ "<<endl;
cout << "/ _| ' \\| '__| |/ _` |"<<endl;
cout << "\\__ \\ |_) | | | | (_| |"<<endl;
cout << "|___/ .__/|_| |_|\\__, |"<<endl;
cout << " | | __/ |"<<endl;
cout << " |_| |___/"<<endl;
cout << "sprig pick <NAME> " <<endl<<"____________"<<endl;
cout << "- downloads sprig <NAME> and saves it as <NAME>.rsmy"<<endl<<endl;
cout << "sprig grow <NAME> <path/to/manifest.json> <path/to/main.rsmy> passwd" <<endl<<"____________"<<endl;
cout << "- Pushes your code to existing package, with authentication required"<<endl<<endl;
cout << "sprig build <NAME> <path/to/main.rsmy> <path/to/manifest.json> <path/to/passwd>" <<endl<<"____________"<<endl;
cout << "builds package <NAME> using provided rsmy, JSON and password files. Throws an error if <NAME> already exists."<<endl<<endl;
}
char cut[]="cut";
if (bob[1]==cut) {
string cmdd;
string cmddpart0="del ";
string cmddpart1=bob[2];
string cmddpart2=".rsmy";
cmdd=cmddpart0+cmddpart1+cmddpart2;
const int length1d = cmdd.length();
char* char_array1d = new char[length1d + 1];
strcpy(char_array1d, cmdd.c_str());
system(char_array1d);
string cmdd1;
string cmddpart01="del ";
string cmddpart11=bob[2];
string cmddpart21=".json";
cmdd1=cmddpart01+cmddpart11+cmddpart21;
const int length1d1 = cmdd.length();
char* char_array1d1 = new char[length1d1 + 1];
strcpy(char_array1d1, cmdd1.c_str());
system(char_array1d1);
}
}
//edit