Skip to content

Commit

Permalink
consolidated changes from other branches here, cleanly (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
robch authored Mar 20, 2024
1 parent 28ddd27 commit 17d5b76
Show file tree
Hide file tree
Showing 78 changed files with 1,341 additions and 918 deletions.
128 changes: 128 additions & 0 deletions ideas/azd-imposter/azd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstring>
#include <sys/stat.h>
#include <sys/types.h>
#include <vector>
#include <algorithm>
#include <istream>
#include <string>
#include <windows.h>

using namespace std;

constexpr char* pathSeparator = ";";
constexpr char* dirSeparator = "\\";
constexpr char* azdBinaryFileName = "azd.exe";
constexpr char* azdFullNameCacheFile = "azd.ini";
constexpr char* azdFullNameMustContains = "Azure Dev CLI";

constexpr char* aiCommandName = "ai";
constexpr char* aiBinaryFileName = "ai.exe";

string findMyself() {
char path[MAX_PATH];
GetModuleFileNameA(NULL, path, MAX_PATH);

auto whereThisBinaryLives = string(path);
auto lastSlash = whereThisBinaryLives.find_last_of(dirSeparator);
if (lastSlash != string::npos) {
whereThisBinaryLives = whereThisBinaryLives.substr(0, lastSlash);
}
else {
whereThisBinaryLives = ".";
}

return whereThisBinaryLives;
}

bool fileExists(const string& name) {
struct stat buffer;
return (stat (name.c_str(), &buffer) == 0);
}

string findAzdBinaryInPath() {
vector<string> paths;
char* path = getenv("PATH");
char* token = strtok(path, pathSeparator);
while (token != NULL) {
paths.push_back(string(token));
token = strtok(NULL, pathSeparator);
}

for (auto& p : paths) {
string withPath = p + std::string(dirSeparator) + azdBinaryFileName;
if (fileExists(withPath) && withPath.find(azdFullNameMustContains) != string::npos) {
return withPath;
}
}

printf("ERROR: `%s` not found in PATH!!\n\n TRY: Update PATH to include location %s...\n OR: Update %s with full path to %s", azdBinaryFileName, azdBinaryFileName, azdFullNameCacheFile, azdBinaryFileName);
exit(1);
}

string findAndCacheAzdBinary()
{
auto whereThisBinaryLives = findMyself();

auto sideBySideCacheFile = whereThisBinaryLives + dirSeparator + azdFullNameCacheFile;
ifstream cacheStream(sideBySideCacheFile);

string cachedContent;
if (cacheStream.good()) {
getline(cacheStream, cachedContent);
cacheStream.close();
} else {
cachedContent = findAzdBinaryInPath();
std::ofstream outFile(sideBySideCacheFile);
outFile << cachedContent;
outFile.close();
}

return cachedContent;
}

string quoteArgIfNeeded(const char* arg) {

bool needsQuoted = false;
string argStr(arg);

if (argStr.find('\"') != string::npos) {
needsQuoted = true;
size_t pos = 0;
while ((pos = argStr.find("\"", pos)) != string::npos) {
argStr.replace(pos, 1, "\\\"");
pos += 2;
}
}

if (argStr.find(' ') != string::npos) {
needsQuoted = true;
}

return needsQuoted
? "\"" + argStr + "\""
: argStr;
}

int main(int argc, char* argv[]) {

auto actualBinaryFullFileName = findAndCacheAzdBinary();

if (argc > 1 && string(argv[1]) == aiCommandName) {
string commandLine(aiBinaryFileName);
for (int i = 2; i < argc; i++) {
commandLine += " ";
commandLine += quoteArgIfNeeded(argv[i]);
}
return system(commandLine.c_str());
} else {
string commandLine("\"" + actualBinaryFullFileName + "\"");
for (int i = 1; i < argc; i++) {
commandLine += " ";
commandLine += quoteArgIfNeeded(argv[i]);
}
return system(commandLine.c_str());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Azure.AI.Details.Common.CLI.Extensions.HelperFunctions;

public static class NutritionHelperFunctions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Azure.AI.Details.Common.CLI.Extensions.HelperFunctions;

public static class PokemonHelperFunctions
Expand Down
10 changes: 5 additions & 5 deletions src/ai/.x/help/dev
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
___ ____ ___ _____ ___ _____ __
/ _ /_ / / _ |/_ _/ / _ \/ __/ | / /
/ __ |/ /_/ __ |_/ /_ / // / _/ | |/ /
/_/ |_/___/_/ |_/____/ /____/___/ |___/

___ _____ ___ _____ __
/ _ |/_ _/ / _ \/ __/ | / /
/ __ |_/ /_ / // / _/ | |/ /
/_/ |_/____/ /____/___/ |___/
USAGE: ai dev <command> [...]

COMMANDS
Expand Down
8 changes: 4 additions & 4 deletions src/ai/.x/help/examples
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
___ ____ ___ _____
/ _ /_ / / _ |/_ _/
/ __ |/ /_/ __ |_/ /_
/_/ |_/___/_/ |_/____/
___ _____
/ _ |/_ _/
/ __ |_/ /_
/_/ |_/____/

USAGE: ai <command> [...]

Expand Down
8 changes: 4 additions & 4 deletions src/ai/.x/help/help
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

___ ____ ___ _____ __ __ ___ _ ___
/ _ /_ / / _ |/_ _/ / // / __/ / / _ \
/ __ |/ /_/ __ |_/ /_ / _ / _// /__/ ___/
/_/ |_/___/_/ |_/____/ /_//_/___/____/_/
___ _____ __ __ ___ _ ___
/ _ |/_ _/ / // / __/ / / _ \
/ __ |_/ /_ / _ / _// /__/ ___/
/_/ |_/____/ /_//_/___/____/_/


`AI HELP`
Expand Down
8 changes: 4 additions & 4 deletions src/ai/.x/help/include.ai.ascii.logo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
___ ____ ___ _____
/ _ /_ / / _ |/_ _/
/ __ |/ /_/ __ |_/ /_
/_/ |_/___/_/ |_/____/
___ _____
/ _ |/_ _/
/ __ |_/ /_
/_/ |_/____/
8 changes: 4 additions & 4 deletions src/ai/.x/help/include.ai.dev.ascii.logo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
___ ____ ___ _____ ___ _____ __
/ _ /_ / / _ |/_ _/ / _ \/ __/ | / /
/ __ |/ /_/ __ |_/ /_ / // / _/ | |/ /
/_/ |_/___/_/ |_/____/ /____/___/ |___/
___ _____ ___ _____ __
/ _ |/_ _/ / _ \/ __/ | / /
/ __ |_/ /_ / // / _/ | |/ /
/_/ |_/____/ /____/___/ |___/
8 changes: 4 additions & 4 deletions src/ai/.x/help/include.ai.dev.shell.ascii.logo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
___ ____ ___ _____ ___ _____ __ ___ __ _ ___ __ __
/ _ /_ / / _ |/_ _/ / _ \/ __/ | / / / __/ // / __/ / / /
/ __ |/ /_/ __ |_/ /_ / // / _/ | |/ / _\ \/ _ / _// /__/ /__
/_/ |_/___/_/ |_/____/ /____/___/ |___/ /___/_//_/___/____/____/
___ _____ ___ _____ __ ___ __ _ ___ __ __
/ _ |/_ _/ / _ \/ __/ | / / / __/ // / __/ / / /
/ __ |_/ /_ / // / _/ | |/ / _\ \/ _ / _// /__/ /__
/_/ |_/____/ /____/___/ |___/ /___/_//_/___/____/____/
8 changes: 4 additions & 4 deletions src/ai/.x/help/include.ai.init.ascii.logo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
___ ____ ___ _____ __ __ __ _ _______
/ _ /_ / / _ |/_ _/ / / |/ / /__ __/
/ __ |/ /_/ __ |_/ /_ / / /| / / / /
/_/ |_/___/_/ |_/____/ /__/_/ |_/__/ /_/
___ _____ __ __ __ _ _______
/ _ |/_ _/ / / |/ / /__ __/
/ __ |_/ /_ / / /| / / / /
/_/ |_/____/ /__/_/ |_/__/ /_/
8 changes: 4 additions & 4 deletions src/ai/.x/help/include.ai.wizard.ascii.logo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
___ ____ ___ _____ _ _ _____ ___ ___ ___ ___
/ _ /_ / / _ |/_ _/ | | /| / /_ _/_ / / _ | / _ \/ _ \
/ __ |/ /_/ __ |_/ /_ | |/ |/ /_/ /_ / /_/ __ |/ , _/ // /
/_/ |_/___/_/ |_/____/ |__/|__/_____//___/_/ |_/_/|_/____/
___ _____ _ _ _____ ___ ___ ___ ___
/ _ |/_ _/ | | /| / /_ _/_ / / _ | / _ \/ _ \
/ __ |_/ /_ | |/ |/ /_/ /_ / /_/ __ |/ , _/ // /
/_/ |_/____/ |__/|__/_____//___/_/ |_/_/|_/____/
8 changes: 4 additions & 4 deletions src/ai/.x/help/include.not.written.yet
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
___ ____ ___ _____
/ _ /_ / / _ |/_ _/
/ __ |/ /_/ __ |_/ /_
/_/ |_/___/_/ |_/____/
___ _____
/ _ |/_ _/
/ __ |_/ /_
/_/ |_/____/


`WARNING`: Help topic not written yet
Expand Down
10 changes: 5 additions & 5 deletions src/ai/.x/help/language
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
___ ____ ___ _____ __
/ _ /_ / / _ |/_ _/ / / ___ ____ ___ ___ _____ ____ ____
/ __ |/ /_/ __ |_/ /_ / /__/ _ \/ _ \/ _ \/ // / _ \/ _ \/ -_)
/_/ |_/___/_/ |_/____/ /____/\_,_/_//_/\_, /\_,_/\_,_/\_, /\__/
/___/ /___/
___ _____ __
/ _ |/_ _/ / / ___ ____ ___ ___ _____ ____ ____
/ __ |_/ /_ / /__/ _ \/ _ \/ _ \/ // / _ \/ _ \/ -_)
/_/ |_/____/ /____/\_,_/_//_/\_, /\_,_/\_,_/\_, /\__/
/___/ /___/

USAGE: ai language <command> [...]

Expand Down
8 changes: 4 additions & 4 deletions src/ai/.x/help/search
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
___ ____ ___ _____ ___________ ___ _______ __
/ _ /_ / / _ |/_ _/ / __/ __/ _ | / _ \/ ___/ // /
/ __ |/ /_/ __ |_/ /_ _\ \/ _// __ |/ , _/ /__/ _ /
/_/ |_/___/_/ |_/____/ /___/___/_/ |_/_/|_|\___/_//_/
___ _____ ___________ ___ _______ __
/ _ |/_ _/ / __/ __/ _ | / _ \/ ___/ // /
/ __ |_/ /_ _\ \/ _// __ |/ , _/ /__/ _ /
/_/ |_/____/ /___/___/_/ |_/_/|_|\___/_//_/

USAGE: ai search <command> [...]

Expand Down
8 changes: 4 additions & 4 deletions src/ai/.x/help/service
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
___ ____ ___ _____ ___________ _ _______________
/ _ /_ / / _ |/_ _/ / __/ __/ _ \ | / / _/ ___/ __/
/ __ |/ /_/ __ |_/ /_ _\ \/ _// , _/ |/ // // /__/ _/
/_/ |_/___/_/ |_/____/ /___/___/_/|_||___/___/\___/___/
___ _____ ___________ _ _______________
/ _ |/_ _/ / __/ __/ _ \ | / / _/ ___/ __/
/ __ |_/ /_ _\ \/ _// , _/ |/ // // /__/ _/
/_/ |_/____/ /___/___/_/|_||___/___/\___/___/

USAGE: ai service <command> [...]

Expand Down
8 changes: 4 additions & 4 deletions src/ai/.x/help/speech/_
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
___ ____ ___ _____ ___ ___ ___ ___ ____ __ __
/ _ /_ / / _ |/_ _/ / __/ _ \/ __/ __/ ___/ // /
/ __ |/ /_/ __ |_/ /_ _\ \/ ___/ _// _// /__/ _ /
/_/ |_/___/_/ |_/____/ /___/_/ /___/___/\___/_//_/
___ _____ ___ ___ ___ ___ ____ __ __
/ _ |/_ _/ / __/ _ \/ __/ __/ ___/ // /
/ __ |_/ /_ _\ \/ ___/ _// _// /__/ _ /
/_/ |_/____/ /___/_/ /___/___/\___/_//_/

USAGE: ai speech <command> [...]

Expand Down
8 changes: 4 additions & 4 deletions src/ai/.x/help/test
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
___ ____ ___ _____ ____________________
/ _ /_ / / _ |/_ _/ /_ __/ __/ __/_ __/
/ __ |/ /_/ __ |_/ /_ / / / _/_\ \ / /
/_/ |_/___/_/ |_/____/ /_/ /___/___/ /_/
___ _____ ____________________
/ _ |/_ _/ /_ __/ __/ __/_ __/
/ __ |_/ /_ / / / _/_\ \ / /
/_/ |_/____/ /_/ /___/___/ /_/

USAGE: ai test <command> [...]

Expand Down
8 changes: 4 additions & 4 deletions src/ai/.x/help/tool
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
___ ____ ___ _____ __________ ____ __
/ _ /_ / / _ |/_ _/ /_ __/ __ \/ __ \/ /
/ __ |/ /_/ __ |_/ /_ / / / /_/ / /_/ / /__
/_/ |_/___/_/ |_/____/ /_/ \____/\____/____/
___ _____ __________ ____ __
/ _ |/_ _/ /_ __/ __ \/ __ \/ /
/ __ |_/ /_ / / / /_/ / /_/ / /__
/_/ |_/____/ /_/ \____/\____/____/


USAGE: ai tool <command> [...]
Expand Down
8 changes: 4 additions & 4 deletions src/ai/.x/help/usage
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
___ ____ ___ _____
/ _ /_ / / _ |/_ _/
/ __ |/ /_/ __ |_/ /_
/_/ |_/___/_/ |_/____/
___ _____
/ _ |/_ _/
/ __ |_/ /_
/_/ |_/____/

USAGE: ai <command> [...]

Expand Down
8 changes: 4 additions & 4 deletions src/ai/.x/help/vision
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
___ ____ ___ _____ _ __________________ _ __
/ _ /_ / / _ |/_ _/ | | / / _/ __/ _/ __ \/ |/ /
/ __ |/ /_/ __ |_/ /_ | |/ // /_\ \_/ // /_/ / /
/_/ |_/___/_/ |_/____/ |___/___/___/___/\____/_/|_/
___ _____ _ __________________ _ __
/ _ |/_ _/ | | / / _/ __/ _/ __ \/ |/ /
/ __ |_/ /_ | |/ // /_\ \_/ // /_/ / /
/_/ |_/____/ |___/___/___/___/\____/_/|_/

USAGE: ai vision <command> [...]

Expand Down
Loading

0 comments on commit 17d5b76

Please sign in to comment.