/ scripts / demo-versioning-cli.sh
demo-versioning-cli.sh
  1  #!/bin/bash
  2  
  3  # Set colors
  4  BLUE='\033[0;34m'
  5  GREEN='\033[0;32m'
  6  RED='\033[0;31m'
  7  YELLOW='\033[0;33m'
  8  NC='\033[0m' # No Color
  9  
 10  # Function to display commands and their output
 11  run_command() {
 12      echo -e "${BLUE}$ $1${NC}"
 13      eval "$1"
 14      echo ""
 15  }
 16  
 17  # Function to create a test file
 18  create_test_file() {
 19      local file=$1
 20      local content=$2
 21      echo "$content" > "$file"
 22      echo -e "${GREEN}Created test file: $file${NC}"
 23      echo ""
 24  }
 25  
 26  # Function to display section header
 27  section() {
 28      echo -e "${YELLOW}========== $1 ==========${NC}"
 29      echo ""
 30  }
 31  
 32  # Create a test directory
 33  TEST_DIR="./versioning-demo"
 34  mkdir -p "$TEST_DIR"
 35  cd "$TEST_DIR"
 36  
 37  # Start the demo
 38  echo -e "${GREEN}KeepSync Versioning CLI Demo${NC}"
 39  echo -e "${GREEN}============================${NC}"
 40  echo ""
 41  
 42  # Create test files
 43  section "Creating Test Files"
 44  create_test_file "document.txt" "This is version 1 of the document.\nIt contains important information."
 45  create_test_file "image.png" "$(dd if=/dev/urandom bs=1024 count=10 2>/dev/null | base64)"
 46  
 47  # List versions
 48  section "Listing Versions"
 49  run_command "keepsync version list document.txt"
 50  
 51  # Create a new version
 52  section "Creating a New Version"
 53  echo -e "${GREEN}Modifying document.txt...${NC}"
 54  echo "This is version 2 of the document.\nIt contains important information.\nThis line was added in version 2." > document.txt
 55  run_command "keepsync version list document.txt"
 56  
 57  # Get a specific version
 58  section "Getting a Specific Version"
 59  run_command "keepsync version get document.txt v1 document-v1.txt"
 60  run_command "cat document-v1.txt"
 61  
 62  # Compare versions
 63  section "Comparing Versions"
 64  run_command "keepsync version diff document.txt v1 v2"
 65  
 66  # Tag management
 67  section "Tag Management"
 68  run_command "keepsync version tag create stable '#00FF00' 'Stable version'"
 69  run_command "keepsync version tag create beta '#FFFF00' 'Beta version'"
 70  run_command "keepsync version tag list"
 71  run_command "keepsync version tag add document.txt v1 stable"
 72  run_command "keepsync version tag add document.txt v2 beta"
 73  run_command "keepsync version list document.txt"
 74  
 75  # Search by tag
 76  section "Searching by Tag"
 77  run_command "keepsync version search by-tag document.txt stable"
 78  
 79  # Add metadata
 80  section "Adding Metadata"
 81  run_command "keepsync version comment document.txt v1 'Initial version with basic content'"
 82  run_command "keepsync version comment document.txt v2 'Added a new line of information'"
 83  run_command "keepsync version author document.txt v1 'John Doe'"
 84  run_command "keepsync version author document.txt v2 'Jane Smith'"
 85  run_command "keepsync version list document.txt"
 86  
 87  # Create more versions
 88  section "Creating More Versions"
 89  echo -e "${GREEN}Creating version 3...${NC}"
 90  echo "This is version 3 of the document.\nIt contains important information.\nThis line was added in version 2.\nThis line was added in version 3." > document.txt
 91  run_command "keepsync version list document.txt"
 92  
 93  echo -e "${GREEN}Creating version 4...${NC}"
 94  echo "This is version 4 of the document.\nIt contains important information.\nThis line was added in version 2.\nThis line was added in version 3.\nThis line was added in version 4." > document.txt
 95  run_command "keepsync version list document.txt"
 96  
 97  echo -e "${GREEN}Creating version 5...${NC}"
 98  echo "This is version 5 of the document.\nIt contains important information.\nThis line was added in version 2.\nThis line was added in version 3.\nThis line was added in version 4.\nThis line was added in version 5." > document.txt
 99  run_command "keepsync version list document.txt"
100  
101  # Purge old versions
102  section "Purging Old Versions"
103  run_command "keepsync version purge document.txt 3"
104  run_command "keepsync version list document.txt"
105  
106  # Restore a version
107  section "Restoring a Version"
108  run_command "keepsync version restore document.txt v3"
109  run_command "cat document.txt"
110  run_command "keepsync version list document.txt"
111  
112  # Delete a version
113  section "Deleting a Version"
114  run_command "keepsync version delete document.txt v4"
115  run_command "keepsync version list document.txt"
116  
117  # Clean up
118  section "Cleaning Up"
119  cd ..
120  rm -rf "$TEST_DIR"
121  echo -e "${GREEN}Demo completed and cleaned up.${NC}"