Skip to content

Instantly share code, notes, and snippets.

@spouliot
Created February 5, 2022 21:40
Show Gist options
  • Save spouliot/755c503e6c7676803e3317fc2b1753f8 to your computer and use it in GitHub Desktop.
Save spouliot/755c503e6c7676803e3317fc2b1753f8 to your computer and use it in GitHub Desktop.
My first gist
using SimpleGist;
if (args.Length == 0) {
Console.WriteLine ("Usage: SimpleGist.exe <file> [<file2> ...]");
return 1;
}
var token = Environment.GetEnvironmentVariable ("GITHUB_OAUTH_TOKEN");
if (token is null) {
var home = Environment.GetEnvironmentVariable ("HOME");
if (home is not null)
token = File.ReadAllText (Path.Combine (home, ".gist"));
}
GistClient.OAuthToken = token;
GistRequest request = new () {
Description = "My first gist",
Public = true,
};
foreach (var arg in args) {
if (!File.Exists (arg)) {
Console.WriteLine ($"File {arg} does not exist");
return 1;
}
request.AddFile (arg, File.ReadAllText (arg));
}
var response = await GistClient.CreateAsync (request);
Console.WriteLine (response.Url);
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment