Skip to content
This repository has been archived by the owner on Sep 27, 2020. It is now read-only.

Commit

Permalink
Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianFun123 committed Nov 24, 2019
0 parents commit 1637368
Show file tree
Hide file tree
Showing 11 changed files with 515 additions and 0 deletions.
30 changes: 30 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Pastefy-CLI

`pastefy -f file.txt`

Out:
<pre><font color="#8AE234">᮰ Done</font>: Pasted! Here is your link https://pastefy.ga/0c6sDILq</pre>


`Examples`
```
pastefy -c "Hello world" -t "test.txt"
pastefy -f test.txt
```

### Installation `Linux`
```bash
sudo wget https://raw.githubusercontent.com/interaapps/pastefy-cli/master/pastefy
sudo mv pastefy /usr/local/bin/pastefy
sudo chmod 777 /usr/local/bin/pastefy
```
`Information` You can also download the `pastefy` file and use `php pastefy` if you don't want to install it globally. (Also works on Windows and MacOS)

### Options
```
-f · File
-p · Password
-c · contents
-t · title
```
56 changes: 56 additions & 0 deletions app/Paste.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace app;

use modules\colorful\Colors;

class Paste {
private $apiURL = "https://pastefy.ga/create:paste";
private $postParams = [
"title"=>"Hi",
"content"=>"Hallo"
];

public function send(){
Colors::info("Sending...");
$headers = [];
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->postParams);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $this->apiURL);
curl_setopt($ch, CURLOPT_HEADERFUNCTION,
function($curl, $header) use (&$headers) {
$len = strlen($header);
$header = explode(':', $header, 2);
if (count($header) < 2)
return $len;
$headers[strtolower(trim($header[0]))][] = trim($header[1]);
return $len;
});

$response = curl_exec($ch);

if (isset($headers["location"][0]))
return "https://pastefy.ga".$headers["location"][0];

Colors::error("A error occured");
exit();
}


public function setContents($contents){
$this->postParams["content"] = $contents;
}

public function setTitle($title){
$this->postParams["title"] = $title;
}

public function setPassword($password){
$this->postParams["password"] = $password;
}



}
15 changes: 15 additions & 0 deletions build.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

$files = [
"app/Paste.php",
"modules/cli/CLI.php",
"modules/colorful/Colors.php",
"main.php"
];

$out = "#!/usr/bin/env php\n";

foreach ($files as $file){
$out .= file_get_contents($file)."\n?>";
}
file_put_contents("pastefy", $out);
46 changes: 46 additions & 0 deletions main.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
chdir(".");

use app\Paste;
use modules\cli\CLI;
use modules\colorful\Colors;

$send = false;
$a = null;
$options = getopt("f:c:p:t:");

$paste = new Paste;

$paste->setTitle("");
$paste->setContents("");


if (isset($options["f"])) {
echo $options["f"];
if (file_exists($options["f"])) {
$paste->setContents(file_get_contents($options["f"]));
$paste->setTitle($options["f"]);
$send = true;
} else Colors::error("File not found");
}

if (isset($options["p"]))
$paste->setPassword($options["p"]);

if (isset($options["c"])) {
$paste->setContents($options["c"]);
$send = true;
}

if (isset($options["t"]))
$paste->setTitle($options["t"]);

if ($send)
Colors::done("Pasted! Here is your link ".$paste->send());
else
Colors::error("Error! Contents not sent
-f · File
-p · Password
-c · contents
-t · title
");
64 changes: 64 additions & 0 deletions modules/cli/CLI.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
namespace modules\cli;

use modules\colorful\Colors;

class CLI {
public $commands = [];
public $descriptions = [];
/**
* Change the not found errormessage
*/
public $errorMessage;
/**
* Shows a list with all commands on function not found error
*/
public $showArgsOnError=true;


/**
* Register a new command
* @param String function-name (Command)
* @param Function function (example:function() {return "Hello world";})
* @param String (Optional) Description
*/
public function register(string $name, $func, string $description="") {
$this->commands[$name] = $func;
$this->descriptions[$name] = $description;
}

/**
* Runs a command
*/
public function run($run) {
if (isset($this->commands[$run])) {
$function = ($this->commands[$run]);
echo $function($run);
} else {
if ($this->errorMessage != null)
echo $this->errorMessage;
else
echo Colors::PREFIX_ERROR."Function \"".$run."\" not found!\n";


if ($this->showArgsOnError) {
$showArgs = Colors::PREFIX_DONE."Those are some valid functions: ";
foreach ($this->commands as $command=>$value) {
$showArgs .= "\n \033[92m- \033[0m".$command.": ".$this->descriptions[$command];
}
echo $showArgs."\n";
}

}
}

public function getCommands(): array {
return $this->commands;
}

public function getDescriptions(): array {
return $this->descriptions;
}
}

?>
42 changes: 42 additions & 0 deletions modules/colorful/Colors.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
namespace modules\colorful;

class Colors {
public const HEADER = "\033[95m",
OKBLUE = "\033[94m",
OKGREEN = "\033[92m",
WARNING = "\033[93m",
FAIL = "\033[91m",
ENDC = "\033[0m",
BOLD = "\033[1m",
UNDERLINE = "\033[4m",
RED = "\033[31m",
BLUE = "\033[34m",
YELLOW = "\033[33m",
TURQUIOUS = "\033[36m",
GREEN = "\033[32m",
BLINK = "\033[5m",
BG_RED = "\033[41m",
BG_BLUE = "\033[44m",
BG_GREEN = "\033[42m",
BG_YELLOW = "\033[43m",
BG_BLACK = "\033[40m";

public const PREFIX_DONE = "\033[92m᮰ Done\033[0m: ",
PREFIX_WARN = "\033[93m᮰ WARNING\033[0m: ",
PREFIX_INFO = "\033[36m᮰ INFO\033[0m: ",
PREFIX_ERROR = "\033[91m᮰ ERROR\033[0m: ";

public static function info($str){
echo self::PREFIX_INFO.$str.self::ENDC."\n";
}
public static function warning($str){
echo self::PREFIX_WARN.$str.self::ENDC."\n";
}
public static function done($str){
echo self::PREFIX_DONE.$str.self::ENDC."\n";
}
public static function error($str){
echo self::PREFIX_ERROR.$str.self::ENDC."\n";
}
}
17 changes: 17 additions & 0 deletions modules/colorful/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# PHP-Colorful! `UPPM`
```php
echo Colors::BLUE."Hello world!".Colors::ENDC;
// Logging outputter
Colors::error("File not found :(!");
```

#### Installation
Download UPPM if you havent
```bash
wget https://raw.githubusercontent.com/interaapps/uppm/master/uppm
```

Installing colorful!
```php
php uppm install colorful
```
13 changes: 13 additions & 0 deletions modules/colorful/uppm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "colorful",
"version": "1.0",
"description": "Make your PHP CLI colorful!",
"author": "JulianFun123",
"keywords": [
"color",
"CLI"
],
"modules": {},
"namespaces": {},
"build": {}
}
Loading

0 comments on commit 1637368

Please sign in to comment.