Continuing work on the CLI functionality. Able to strip the command line actions, and flags with their values #7
This commit is contained in:
@@ -43,6 +43,7 @@ endif()
|
|||||||
set(SOURCES
|
set(SOURCES
|
||||||
src/Main.cpp
|
src/Main.cpp
|
||||||
src/Managers/ActionManager.cpp
|
src/Managers/ActionManager.cpp
|
||||||
|
src/Managers/CommitManager.cpp
|
||||||
src/Managers/FileManager.cpp
|
src/Managers/FileManager.cpp
|
||||||
src/Syncers/Download.cpp
|
src/Syncers/Download.cpp
|
||||||
src/Syncers/Upload.cpp
|
src/Syncers/Upload.cpp
|
||||||
@@ -50,9 +51,14 @@ set(SOURCES
|
|||||||
)
|
)
|
||||||
set(HEADERS
|
set(HEADERS
|
||||||
src/Managers/ActionManager.h
|
src/Managers/ActionManager.h
|
||||||
|
src/Managers/CommitManager.h
|
||||||
src/Managers/FileManager.h
|
src/Managers/FileManager.h
|
||||||
|
src/Models/Token.h
|
||||||
|
src/Models/Flags.h
|
||||||
|
src/Models/IcarusAction.h
|
||||||
src/Models/Song.h
|
src/Models/Song.h
|
||||||
src/Models/UploadForm.h
|
src/Models/UploadForm.h
|
||||||
|
src/Models/User.h
|
||||||
src/Syncers/Download.h
|
src/Syncers/Download.h
|
||||||
src/Syncers/Upload.h
|
src/Syncers/Upload.h
|
||||||
src/Utilities/Conversions.h
|
src/Utilities/Conversions.h
|
||||||
|
|||||||
+6
-1
@@ -2,6 +2,7 @@
|
|||||||
#include<string>
|
#include<string>
|
||||||
|
|
||||||
#include"Managers/ActionManager.h"
|
#include"Managers/ActionManager.h"
|
||||||
|
#include"Managers/CommitManager.h"
|
||||||
|
|
||||||
using std::cin;
|
using std::cin;
|
||||||
using std::cout;
|
using std::cout;
|
||||||
@@ -9,20 +10,24 @@ using std::endl;
|
|||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
using Managers::ActionManager;
|
using Managers::ActionManager;
|
||||||
|
using Managers::CommitManager;
|
||||||
|
|
||||||
string songPath{};
|
string songPath{};
|
||||||
string newSongPath{};
|
string newSongPath{};
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
if (argc <= 1)
|
if (argc < 2)
|
||||||
{
|
{
|
||||||
cout<<"No actions provided"<<endl;
|
cout<<"No actions provided"<<endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ActionManager actMgr{argv};
|
ActionManager actMgr{argv};
|
||||||
|
auto chosenAction = actMgr.retrieveIcarusAction();
|
||||||
|
|
||||||
|
CommitManager commitMgr{chosenAction};
|
||||||
|
commitMgr.commitAction();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,185 @@
|
|||||||
#include"ActionManager.h"
|
#include"ActionManager.h"
|
||||||
|
#include<algorithm>
|
||||||
|
#include<iostream>
|
||||||
|
#include<exception>
|
||||||
|
#include<cstring>
|
||||||
|
|
||||||
|
using std::cout;
|
||||||
|
using std::endl;
|
||||||
|
using std::string;
|
||||||
|
using std::vector;
|
||||||
|
|
||||||
|
using Models::Flags;
|
||||||
|
using Models::IcarusAction;
|
||||||
|
|
||||||
namespace Managers
|
namespace Managers
|
||||||
{
|
{
|
||||||
#pragma
|
#pragma
|
||||||
ActionManager::ActionManager(char** param)
|
ActionManager::ActionManager(char **param)
|
||||||
{
|
{
|
||||||
// TODO: Implement what to do
|
this->params = param;
|
||||||
// wih the parameters
|
|
||||||
|
action = string{params[1]};
|
||||||
|
transform(action.begin(), action.end(),
|
||||||
|
action.begin(), ::tolower);
|
||||||
|
|
||||||
|
initialize();
|
||||||
}
|
}
|
||||||
#pragma Constructors
|
#pragma Constructors
|
||||||
|
|
||||||
|
|
||||||
|
#pragma
|
||||||
|
IcarusAction ActionManager::retrieveIcarusAction() const
|
||||||
|
{
|
||||||
|
auto icarusAction = IcarusAction{};
|
||||||
|
icarusAction.flags = flags;
|
||||||
|
icarusAction.action = action;
|
||||||
|
|
||||||
|
return icarusAction;
|
||||||
|
}
|
||||||
|
vector<Flags> ActionManager::retrieveFlags() const
|
||||||
|
{
|
||||||
|
return flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
string ActionManager::retrieveAction() const
|
||||||
|
{
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ActionManager::initialize()
|
||||||
|
{
|
||||||
|
initializeSupportedActions();
|
||||||
|
validateAction();
|
||||||
|
validateFlags();
|
||||||
|
}
|
||||||
|
void ActionManager::initializeSupportedActions()
|
||||||
|
{
|
||||||
|
supportedActions = vector<string>{
|
||||||
|
"download", "delete",
|
||||||
|
"retrieve", "upload"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
void ActionManager::initializeSupportedFlags()
|
||||||
|
{
|
||||||
|
supportedFlags = vector<string>{
|
||||||
|
"-u", "-p", "-t", "-h", "-s",
|
||||||
|
"-d"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
void ActionManager::validateAction()
|
||||||
|
{
|
||||||
|
cout<<"Validating action"<<endl;
|
||||||
|
|
||||||
|
if (std::any_of(supportedActions.begin(), supportedActions.end(),
|
||||||
|
[&](string val)
|
||||||
|
{
|
||||||
|
return !val.compare(action);
|
||||||
|
}))
|
||||||
|
{
|
||||||
|
cout<<"Action: "<<action<<" is valid"<<endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cout<<"Action is not valid"<<endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void ActionManager::validateFlags()
|
||||||
|
{
|
||||||
|
cout<<"Validating flags"<<endl;
|
||||||
|
|
||||||
|
auto flagVals = parsedFlags();
|
||||||
|
initializeSupportedFlags();
|
||||||
|
|
||||||
|
Flags flg{};
|
||||||
|
|
||||||
|
for (auto flag : flagVals)
|
||||||
|
{
|
||||||
|
if (flag.size() > 3)
|
||||||
|
{
|
||||||
|
flg.value = flag;
|
||||||
|
flags.push_back(flg);
|
||||||
|
flg = Flags{};
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
cout<<"\nprovided flag: "<<flag<<endl;
|
||||||
|
if (std::any_of(supportedFlags.begin(), supportedFlags.end(),
|
||||||
|
[&](string val)
|
||||||
|
{
|
||||||
|
if (val.size() < 3)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
return !val.compare(flag);
|
||||||
|
}))
|
||||||
|
{
|
||||||
|
cout<<"Flag : "<<flag<<" is valid"<<endl;
|
||||||
|
flg.flag = flag;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cout<<"Action is not valid"<<endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<string> ActionManager::parsedFlags()
|
||||||
|
{
|
||||||
|
auto parsed = vector<string>{};
|
||||||
|
try
|
||||||
|
{
|
||||||
|
for (auto i = 2; true; ++i)
|
||||||
|
{
|
||||||
|
string val{*(params + i)};
|
||||||
|
parsed.push_back(val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (std::exception e)
|
||||||
|
{
|
||||||
|
auto msg = e.what();
|
||||||
|
cout<<"This happend: "<<msg<<endl<<endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return parsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma
|
||||||
|
void ActionManager::printAction()
|
||||||
|
{
|
||||||
|
if (action.empty())
|
||||||
|
{
|
||||||
|
printf("Action is empty\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cout<<"Action is "<<action<<endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void ActionManager::printFlags(vector<string> flagVals)
|
||||||
|
{
|
||||||
|
if (flagVals.empty())
|
||||||
|
{
|
||||||
|
printf("Flags and values are empty\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("Printing flags and values..\n");
|
||||||
|
for (auto flgVal : flagVals)
|
||||||
|
{
|
||||||
|
cout<<flgVal<<endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void ActionManager::printFlags()
|
||||||
|
{
|
||||||
|
cout<<"\nPrinting flags..."<<endl;
|
||||||
|
for (auto flag: flags)
|
||||||
|
{
|
||||||
|
cout<<"flag "<<flag.flag<<endl;
|
||||||
|
cout<<"value "<<flag.value<<endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#pragma Testing
|
||||||
|
#pragma Functions
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,40 @@
|
|||||||
#ifndef ACTIONMANAGER_H_
|
#ifndef ACTIONMANAGER_H_
|
||||||
#define ACTIONMANAGER_H_
|
#define ACTIONMANAGER_H_
|
||||||
|
|
||||||
|
#include<string>
|
||||||
|
#include<vector>
|
||||||
|
|
||||||
|
#include"Models/Flags.h"
|
||||||
|
#include"Models/IcarusAction.h"
|
||||||
|
|
||||||
namespace Managers
|
namespace Managers
|
||||||
{
|
{
|
||||||
class ActionManager
|
class ActionManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ActionManager(char**);
|
ActionManager(char**);
|
||||||
|
|
||||||
|
Models::IcarusAction retrieveIcarusAction() const;
|
||||||
|
std::vector<Models::Flags> retrieveFlags() const;
|
||||||
|
std::string retrieveAction() const;
|
||||||
private:
|
private:
|
||||||
|
void initialize();
|
||||||
|
void initializeSupportedActions();
|
||||||
|
void initializeSupportedFlags();
|
||||||
|
void validateAction();
|
||||||
|
void validateFlags();
|
||||||
|
|
||||||
|
std::vector<std::string> parsedFlags();
|
||||||
|
|
||||||
|
void printAction();
|
||||||
|
void printFlags(std::vector<std::string>);
|
||||||
|
void printFlags();
|
||||||
|
|
||||||
|
std::string action;
|
||||||
|
std::vector<std::string> supportedActions;
|
||||||
|
std::vector<std::string> supportedFlags;
|
||||||
|
std::vector<Models::Flags> flags;
|
||||||
|
char **params;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
#include"CommitManager.h"
|
||||||
|
|
||||||
|
#include<iostream>
|
||||||
|
|
||||||
|
using std::cout;
|
||||||
|
using std::endl;
|
||||||
|
using std::map;
|
||||||
|
using std::string;
|
||||||
|
|
||||||
|
using Models::IcarusAction;
|
||||||
|
|
||||||
|
namespace Managers
|
||||||
|
{
|
||||||
|
#pragma
|
||||||
|
CommitManager::CommitManager(IcarusAction icaAct)
|
||||||
|
{
|
||||||
|
icaAction = icaAct;
|
||||||
|
initializeMapActions();
|
||||||
|
}
|
||||||
|
#pragma Constructors;
|
||||||
|
|
||||||
|
|
||||||
|
#pragma
|
||||||
|
void CommitManager::commitAction()
|
||||||
|
{
|
||||||
|
auto action = icaAction.action;
|
||||||
|
cout<<"Commitning "<<action<<" action"<<endl;
|
||||||
|
switch (mapActions[action])
|
||||||
|
{
|
||||||
|
case deleteAct:
|
||||||
|
break;
|
||||||
|
case downloadAct:
|
||||||
|
break;
|
||||||
|
case retrieveAct:
|
||||||
|
break;
|
||||||
|
case uploadAct:
|
||||||
|
uploadSong();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CommitManager::initializeMapActions()
|
||||||
|
{
|
||||||
|
mapActions = map<string, ActionValues>{
|
||||||
|
{"delete", deleteAct}, {"download", downloadAct},
|
||||||
|
{"retrieve", retrieveAct},
|
||||||
|
{"upload", uploadAct}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
void CommitManager::uploadSong()
|
||||||
|
{
|
||||||
|
cout<<"Uploading song..."<<endl;
|
||||||
|
// TODO: Implement functionality for uploading
|
||||||
|
//
|
||||||
|
// Need to the following:
|
||||||
|
// 1. Parse the login credentials from the Flag model
|
||||||
|
// 2. Retrieve a token -- implement token management
|
||||||
|
// 3. Parse song path from the Flag model
|
||||||
|
// 4. Parse the HTTP API endpoint
|
||||||
|
// 5. Upload the song
|
||||||
|
}
|
||||||
|
#pragma Functions
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
#ifndef COMMITMANAGER_H_
|
||||||
|
#define COMMITMANAGER_H_
|
||||||
|
|
||||||
|
#include<map>
|
||||||
|
#include<string>
|
||||||
|
|
||||||
|
#include"Models/IcarusAction.h"
|
||||||
|
|
||||||
|
namespace Managers
|
||||||
|
{
|
||||||
|
class CommitManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CommitManager(Models::IcarusAction);
|
||||||
|
|
||||||
|
void commitAction();
|
||||||
|
private:
|
||||||
|
void initializeMapActions();
|
||||||
|
void uploadSong();
|
||||||
|
|
||||||
|
enum ActionValues
|
||||||
|
{
|
||||||
|
deleteAct,
|
||||||
|
downloadAct,
|
||||||
|
retrieveAct,
|
||||||
|
uploadAct
|
||||||
|
};
|
||||||
|
std::map<std::string, ActionValues> mapActions;
|
||||||
|
Models::IcarusAction icaAction;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#ifndef FLAGS_H_
|
||||||
|
#define FLAGS_H_
|
||||||
|
|
||||||
|
#include<string>
|
||||||
|
|
||||||
|
namespace Models
|
||||||
|
{
|
||||||
|
struct Flags
|
||||||
|
{
|
||||||
|
std::string flag;
|
||||||
|
std::string value;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#ifndef ICARUSACTION_H_
|
||||||
|
#define ICARUSACTION_H_
|
||||||
|
|
||||||
|
#include<string>
|
||||||
|
#include<vector>
|
||||||
|
|
||||||
|
#include"Flags.h"
|
||||||
|
|
||||||
|
namespace Models
|
||||||
|
{
|
||||||
|
struct IcarusAction
|
||||||
|
{
|
||||||
|
std::string action;
|
||||||
|
std::vector<Flags> flags;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -16,6 +16,7 @@ namespace Models
|
|||||||
int year;
|
int year;
|
||||||
int duration;
|
int duration;
|
||||||
char* songData;
|
char* songData;
|
||||||
|
std::string songPath;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
#ifndef TOKEN_H_
|
||||||
|
#define TOKEN_H_
|
||||||
|
|
||||||
|
#include<string>
|
||||||
|
|
||||||
|
namespace Models
|
||||||
|
{
|
||||||
|
struct Token
|
||||||
|
{
|
||||||
|
std::string accessToken;
|
||||||
|
std::string tokenType;
|
||||||
|
int expiration;
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#ifndef USER_H_
|
||||||
|
#define USER_H_
|
||||||
|
|
||||||
|
#include<string>
|
||||||
|
|
||||||
|
namespace Models
|
||||||
|
{
|
||||||
|
struct User
|
||||||
|
{
|
||||||
|
std::string username;
|
||||||
|
std::string password;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user