Continuing work on the CLI functionality. Able to strip the command line actions, and flags with their values #7
This commit is contained in:
+6
-1
@@ -2,6 +2,7 @@
|
||||
#include<string>
|
||||
|
||||
#include"Managers/ActionManager.h"
|
||||
#include"Managers/CommitManager.h"
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
@@ -9,20 +10,24 @@ using std::endl;
|
||||
using std::string;
|
||||
|
||||
using Managers::ActionManager;
|
||||
using Managers::CommitManager;
|
||||
|
||||
string songPath{};
|
||||
string newSongPath{};
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc <= 1)
|
||||
if (argc < 2)
|
||||
{
|
||||
cout<<"No actions provided"<<endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
ActionManager actMgr{argv};
|
||||
auto chosenAction = actMgr.retrieveIcarusAction();
|
||||
|
||||
CommitManager commitMgr{chosenAction};
|
||||
commitMgr.commitAction();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,185 @@
|
||||
#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
|
||||
{
|
||||
#pragma
|
||||
ActionManager::ActionManager(char** param)
|
||||
ActionManager::ActionManager(char **param)
|
||||
{
|
||||
// TODO: Implement what to do
|
||||
// wih the parameters
|
||||
this->params = param;
|
||||
|
||||
action = string{params[1]};
|
||||
transform(action.begin(), action.end(),
|
||||
action.begin(), ::tolower);
|
||||
|
||||
initialize();
|
||||
}
|
||||
#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_
|
||||
#define ACTIONMANAGER_H_
|
||||
|
||||
#include<string>
|
||||
#include<vector>
|
||||
|
||||
#include"Models/Flags.h"
|
||||
#include"Models/IcarusAction.h"
|
||||
|
||||
namespace Managers
|
||||
{
|
||||
class ActionManager
|
||||
{
|
||||
public:
|
||||
ActionManager(char**);
|
||||
|
||||
Models::IcarusAction retrieveIcarusAction() const;
|
||||
std::vector<Models::Flags> retrieveFlags() const;
|
||||
std::string retrieveAction() const;
|
||||
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 duration;
|
||||
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