├── docs ├── .nojekyll ├── _navbar.md ├── README.md ├── index.html ├── quickstart.md └── commands.md ├── main.go ├── assets ├── dotman_logo.png ├── dotman_banner.png └── installation.png ├── .deepsource.toml ├── .editorconfig ├── go.mod ├── .github └── workflows │ └── go.yml ├── TODO.txt ├── README.md ├── go.sum ├── linux_installer.sh ├── handler.go ├── types.go ├── LICENSE └── utils.go /docs/.nojekyll: -------------------------------------------------------------------------------- 1 | ./docs -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | Handle() 5 | } 6 | -------------------------------------------------------------------------------- /assets/dotman_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/d3r1n/dotman/HEAD/assets/dotman_logo.png -------------------------------------------------------------------------------- /assets/dotman_banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/d3r1n/dotman/HEAD/assets/dotman_banner.png -------------------------------------------------------------------------------- /assets/installation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/d3r1n/dotman/HEAD/assets/installation.png -------------------------------------------------------------------------------- /.deepsource.toml: -------------------------------------------------------------------------------- 1 | version = 1 2 | 3 | [[analyzers]] 4 | name = "go" 5 | 6 | [analyzers.meta] 7 | import_root = "github.com/d3r1n/dotman" 8 | 9 | [[transformers]] 10 | name = "gofumpt" -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: https://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | [*] 7 | indent_style = space 8 | indent_size = 4 9 | end_of_line = lf 10 | charset = utf-8 11 | trim_trailing_whitespace = false 12 | insert_final_newline = false -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module dotman 2 | 3 | go 1.17 4 | 5 | require github.com/5elenay/ezcli v1.2.0 6 | 7 | require ( 8 | github.com/fatih/color v1.13.0 9 | github.com/tidwall/pretty v1.2.0 10 | ) 11 | 12 | require ( 13 | github.com/mattn/go-colorable v0.1.9 // indirect 14 | github.com/mattn/go-isatty v0.0.14 // indirect 15 | golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect 16 | ) 17 | -------------------------------------------------------------------------------- /.github/workflows/go.yml: -------------------------------------------------------------------------------- 1 | name: Go 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | 11 | build: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v2 15 | 16 | - name: Set up Go 17 | uses: actions/setup-go@v2 18 | with: 19 | go-version: 1.17 20 | 21 | - name: Build 22 | run: go build -v ./... 23 | -------------------------------------------------------------------------------- /TODO.txt: -------------------------------------------------------------------------------- 1 | ? : not sure 2 | + : will be implemented 3 | - : will not be implemented 4 | --------------------------- 5 | 6 | [X] - Init, Add, Remove, Update, Install Commands (+) // Install Will be implemented in version 0.3 7 | 8 | [X] - Check if dotman.json exists (+) 9 | 10 | [X] - git integration (+) 11 | 12 | [X] - Colored output (+) 13 | 14 | [] - Automatically Update dotfiles (+) // checking every 1 hour to see if dotfiles changed // will be implemented in version 0.3 15 | 16 | [] - Generate Log output (+) 17 | 18 | [] - Custom Scripts can be executed in installation stage (+) 19 | 20 | [] - Auto updater from github releases (?) -------------------------------------------------------------------------------- /docs/_navbar.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | * Quick Start 4 | 5 | * [Quick start](quickstart.md) 6 | * [Initialize a dot]() 7 | * [Add your first dotfile]() 8 | * [Updates!]() 9 | * [Installers and commands]() 10 | * [Check the status of your dot]() 11 | 12 | * Commands 13 | * [Commands](commands) 14 | * [**dotman init**](commands?id=dotman-init) 15 | * [**dotman add**](commands?id=dotman-add) 16 | * [**dotman remove**](commands?id=dotman-remove) 17 | * [**dotman update**](commands?id=dotman-update) 18 | * [**dotman installer**](commands?id=dotman-installer) 19 | * [**dotman command**](commands?id=dotman-command) 20 | * [**dotman generate**](commands?id=dotman-generate) 21 | * [**dotman status**](commands?id=dotman-status) -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # dotman (.man) Docs 2 | 3 | Extended documentation for dotman. 4 | 5 | For a quick tour of dotman and its features, I recommend \ 6 | to start with **Quick Start Guide** 7 | 8 | # Sections 9 | 10 | ## Quick Start 11 | - [Quick Start](quickstart) 12 | - [Installation](quickstart?id=installation) 13 | - [Dotfiles](quickstart?id=dotfiles) 14 | - [Updating](quickstart?id=updating) 15 | - [Installers](quickstart?id=installers) 16 | - [Commands](quickstart?id=commands) 17 | - [Generating](quickstart?id=generating) 18 | --- 19 | ## Commands 20 | - [Commands](commands) 21 | - [ dotman init ](commands?id=dotman-init) 22 | - [ dotman add ](commands?id=dotman-add) 23 | - [ dotman remove ](commands?id=dotman-remove) 24 | - [ dotman update ](commands?id=dotman-update) 25 | - [ dotman installer ](commands?id=dotman-installer) 26 | - [ dotman command ](commands?id=dotman-command) 27 | - [ dotman generate ](commands?id=dotman-generate) 28 | - [ dotman status ](commands?id=dotman-status) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | dotman's logo 4 | 5 |
6 | 7 | # Dotman 8 | better manager for your dotfiles. 9 | 10 | ## Documentation 11 | 12 | Dotman documentation is up!! 13 | check it out at [**d3r1n.github.io/dotman**](https://d3r1n.github.io/dotman) 14 | 15 | ## Version History 16 | - v0.4 [Now] 17 | * Better Documentation - [Main Feature] 18 | * Website? - [Main Feature] 19 | * Multiple Installer Scripts - [Main Feature] 20 | - v0.3 21 | * Automatic Generated installer script - [Main Feature] 22 | * Status Commands 23 | * Dotman Binary installing script 24 | * Bug fixes 25 | - v0.2 26 | * Automatic git support added - [Main Feature] 27 | * Lots of bug fixes 28 | - v0.1 29 | * Initial version of Dotman 30 | 31 | ## Installation 32 | 33 | Just Execute this command to install the dotman from source 34 | 35 | ![Installation](./assets/installation.png) 36 | 37 | **Requirements**: 38 | - Go **1.17** or *higher*. 39 | 40 | ```bash 41 | curl -L https://git.io/J68cu | bash 42 | ``` 43 | **or** 44 | 45 | ```bash 46 | curl https://raw.githubusercontent.com/d3r1n/dotman/master/linux_installer.sh | bash 47 | ``` 48 | 49 | 50 | 51 |
52 | 53 | If you liked this project please leave a star, it helps a lot :3 54 | 55 |
56 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | dotman 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/5elenay/ezcli v1.2.0 h1:5VtQJkyxqAUhQxF6SADbLkLHkg5shn0cQ3pmaf888e8= 2 | github.com/5elenay/ezcli v1.2.0/go.mod h1:dlKSmbQb8PdQaLumV1fYw24GApE3yd9gVnu0bPyNddA= 3 | github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= 4 | github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= 5 | github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U= 6 | github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= 7 | github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= 8 | github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= 9 | github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= 10 | github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= 11 | github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= 12 | golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 13 | golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 14 | golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I= 15 | golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 16 | -------------------------------------------------------------------------------- /linux_installer.sh: -------------------------------------------------------------------------------- 1 | # Colored Output 2 | 3 | # Reset 4 | Color_Off='\033[0m' # Text Reset 5 | 6 | # Regular Colors 7 | Black='\033[0;30m' # Black 8 | Red='\033[0;31m' # Red 9 | Green='\033[0;32m' # Green 10 | Yellow='\033[0;33m' # Yellow 11 | Blue='\033[0;34m' # Blue 12 | Purple='\033[0;35m' # Purple 13 | Cyan='\033[0;36m' # Cyan 14 | White='\033[0;37m' # White 15 | 16 | # Bold 17 | BBlack='\033[1;30m' # Black 18 | BRed='\033[1;31m' # Red 19 | BGreen='\033[1;32m' # Green 20 | BYellow='\033[1;33m' # Yellow 21 | BBlue='\033[1;34m' # Blue 22 | BPurple='\033[1;35m' # Purple 23 | BCyan='\033[1;36m' # Cyan 24 | BWhite='\033[1;37m' # White 25 | 26 | # install Function 27 | function install() { 28 | printf "${BWhite}" 29 | printf "\n --- Dotman Installer --- \n" 30 | printf "https://github.com/d3r1n/dotman\n" 31 | printf "${Color_Off}" 32 | printf "\n" 33 | 34 | printf "${BPurple}" 35 | printf "Cloning Repository..." 36 | printf "${Color_Off}" 37 | 38 | git clone https://github.com/d3r1n/dotman.git 39 | 40 | printf "${BPurple}" 41 | printf "\nBuilding Dotman...\n" 42 | printf "${Color_Off}" 43 | 44 | cd ./dotman 45 | go get github.com/5elenay/ezcli 46 | go get github.com/fatih/color 47 | go get github.com/tidwall/pretty 48 | go build 49 | 50 | printf "${BPurple}" 51 | printf "\nMoving Executable to /bin/ ..\n." 52 | printf "${Color_Off}" 53 | 54 | sudo mv ./dotman /usr/bin/ 55 | 56 | printf "${BPurple}" 57 | printf "\nCleaning...\n" 58 | printf "${Color_Off}" 59 | 60 | cd .. 61 | rm -rf ./dotman 62 | } 63 | 64 | install 65 | -------------------------------------------------------------------------------- /handler.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/5elenay/ezcli" 5 | ) 6 | 7 | func Handle() { 8 | var handler *ezcli.CommandHandler = ezcli.NewApp("dotman") 9 | 10 | handler.AddCommand(&ezcli.Command{ 11 | Name: "init", 12 | Description: "initialize the \"dotman.json\" file", 13 | Options: []*ezcli.CommandOption{ 14 | { 15 | Name: "description", 16 | Description: "Set the description of the dotfiles (optional)", 17 | Aliases: []string{"d", "desc"}, 18 | }, 19 | { 20 | Name: "install_path", 21 | Description: "Set the installation path of the dotfiles (optional)", 22 | Aliases: []string{"i", "ip"}, 23 | }, 24 | { 25 | Name: "remote", 26 | Description: "Set the remote git url of the dotfiles (optional)", 27 | Aliases: []string{"r"}, 28 | }, 29 | { 30 | Name: "branch", 31 | Description: "Set the installation path of the dotfiles (optional)", 32 | Aliases: []string{"b"}, 33 | }, 34 | { 35 | Name: "git", 36 | Description: "Initiliaze a git repository for the dotfiles (default: false)", 37 | Aliases: []string{"g"}, 38 | }, 39 | }, 40 | Execute: func(c *ezcli.Command) { 41 | Init(c) 42 | }, 43 | }) 44 | 45 | handler.AddCommand(&ezcli.Command{ 46 | Name: "add", 47 | Description: "Add a dotfile ", 48 | Options: []*ezcli.CommandOption{ 49 | { 50 | Name: "description", 51 | Description: "Set the description of the dotfile (optional)", 52 | Aliases: []string{"d", "desc"}, 53 | }, 54 | { 55 | Name: "priority", 56 | Description: "Set the priority of the dotfile (optional)", 57 | Aliases: []string{"p", "prio"}, 58 | }, 59 | }, 60 | Execute: func(c *ezcli.Command) { 61 | Add(c) 62 | }, 63 | }) 64 | 65 | handler.AddCommand(&ezcli.Command{ 66 | Name: "remove", 67 | Description: "Remove a dotfile ", 68 | Aliases: []string{"rm"}, 69 | Execute: func(c *ezcli.Command) { 70 | Remove(c) 71 | }, 72 | }) 73 | 74 | handler.AddCommand(&ezcli.Command{ 75 | Name: "update", 76 | Description: "Update a dotfile ", 77 | Aliases: []string{"up"}, 78 | Execute: func(c *ezcli.Command) { 79 | Update(c) 80 | }, 81 | }) 82 | 83 | handler.AddCommand(&ezcli.Command{ 84 | Name: "command", 85 | Description: "Command utilities", 86 | Aliases: []string{"cmd"}, 87 | Options: []*ezcli.CommandOption{ 88 | { 89 | Name: "sudo", 90 | Description: "determine the sudo usage for the command", 91 | Aliases: []string{"s"}, 92 | }, 93 | }, 94 | Execute: func(c *ezcli.Command) { 95 | CommandHandler(c) 96 | }, 97 | }) 98 | 99 | handler.AddCommand(&ezcli.Command{ 100 | Name: "installer", 101 | Description: "installer utilities", 102 | Aliases: []string{"cmd"}, 103 | Options: []*ezcli.CommandOption{ 104 | { 105 | Name: "description", 106 | Description: "add description", 107 | Aliases: []string{"d"}, 108 | }, 109 | }, 110 | Execute: func(c *ezcli.Command) { 111 | InstallerHandler(c) 112 | }, 113 | }) 114 | 115 | handler.AddCommand(&ezcli.Command{ 116 | Name: "generate", 117 | Description: "Generates Installer Script", 118 | Aliases: []string{"gen"}, 119 | Execute: func(c *ezcli.Command) { 120 | Install(c) 121 | }, 122 | }) 123 | 124 | handler.AddCommand(&ezcli.Command{ 125 | Name: "status", 126 | Description: "Shows the status of the dotfiles", 127 | Aliases: []string{"ss"}, 128 | Execute: func(c *ezcli.Command) { 129 | Status(c) 130 | }, 131 | }) 132 | 133 | handler.Handle() 134 | } 135 | -------------------------------------------------------------------------------- /types.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | const ( 4 | FILES_PATH string = "./files/" 5 | INSTALLERS_PATH string = "./installers/" 6 | ) 7 | 8 | type Config struct { 9 | Name string // name of the Dotfile Project (required) 10 | Description string // description of the Dotfile Project (optional) (default: "No Description Provided") 11 | InstallPath string // path to the installation (required) 12 | 13 | // if true, a git repo will be initialized and 14 | // automatically updated with every action (optional) (default: false) 15 | Git bool 16 | 17 | Repository GitConfig 18 | Dotfiles []Dotfile 19 | Installers []Installer 20 | } 21 | 22 | type GitConfig struct { 23 | RemoteName string // name of the git repository (required) 24 | RemoteUrl string // name of the git repository (required) 25 | Branch string // branch name of the git repository (optional) (default: "master") 26 | } 27 | 28 | type Dotfile struct { 29 | Name string // the name of the dotfile (required) 30 | Description string // the description of the dotfile (optional) (default: "No Description Provided") 31 | Location string // the location of the dotfile (required) 32 | Type string // the type of the dotfile (auto) (file, directory) 33 | Priority int64 // the priority of the dotfile (optional) (default: 1) (1-3) 34 | LastUpdate string // the last update date of the dotfile (auto) 35 | } 36 | 37 | type Installer struct { 38 | Name string // the name of the installer (required) 39 | Description string // the description of the installer (optional) (default: "No Description Provided") 40 | Commands []Command // the command to execute the installer (required) 41 | } 42 | 43 | type Command struct { 44 | Execute string // actual command (required) 45 | Sudo bool // whether the command should be executed in sudo mode (optional) (default: false) 46 | } 47 | 48 | type Tmpl struct { 49 | InstallPath string 50 | Installer Installer 51 | } 52 | 53 | /* Template For The Installer Script */ 54 | 55 | // I hate go templates >:[ 56 | 57 | const installer_template = ` 58 | 59 | # ----------------------------------- 60 | # | | 61 | # | Dotman Installer | 62 | # | https://github.com/d3r1n/dotman | 63 | # | | 64 | # ----------------------------------- 65 | 66 | # Colored Output 67 | 68 | # Reset 69 | Color_Off='\033[0m' # Text Reset 70 | 71 | # Regular Colors 72 | Black='\033[0;30m' # Black 73 | Red='\033[0;31m' # Red 74 | Green='\033[0;32m' # Green 75 | Yellow='\033[0;33m' # Yellow 76 | Blue='\033[0;34m' # Blue 77 | Purple='\033[0;35m' # Purple 78 | Cyan='\033[0;36m' # Cyan 79 | White='\033[0;37m' # White 80 | 81 | # Bold 82 | BBlack='\033[1;30m' # Black 83 | BRed='\033[1;31m' # Red 84 | BGreen='\033[1;32m' # Green 85 | BYellow='\033[1;33m' # Yellow 86 | BBlue='\033[1;34m' # Blue 87 | BPurple='\033[1;35m' # Purple 88 | BCyan='\033[1;36m' # Cyan 89 | BWhite='\033[1;37m' # White 90 | 91 | # Installation Location 92 | install_path={{ .InstallPath }} 93 | 94 | # Setup Function 95 | function setup_point() { 96 | printf "${BWhite}" 97 | printf "\n --- Dotman Installer --- \n" 98 | printf "https://github.com/d3r1n/dotman\n" 99 | printf "${Color_Off}" 100 | printf "\n" 101 | printf "Copying Files from ${BBlue}./files/${Color_Off} to ${BBlue}${install_path}${Color_Off}\n" 102 | cp -r ./files/* $install_path 103 | 104 | printf "${BWhite}" 105 | printf "\n --- User Defined Commands --- \n" 106 | printf "${Color_Off}" 107 | printf "\n" 108 | } 109 | 110 | # User defined commands 111 | function run_point() { 112 | {{ range .Installer.Commands }} 113 | {{ if .Sudo }} 114 | sudo {{ .Execute}} 115 | {{ else }} 116 | {{ .Execute }} 117 | {{ end }} 118 | {{ end }} 119 | } 120 | 121 | # Entry points 122 | setup_point 123 | run_point 124 | ` 125 | -------------------------------------------------------------------------------- /docs/quickstart.md: -------------------------------------------------------------------------------- 1 | # Welcome to the Quick Start Guide! 2 | 3 | In this guide we will learn how to use dotman to create dotfiles. \ 4 | This guide is intended to be a quick introduction to dotman and its features. \ 5 | We will cover the following topics: 6 | - Installation 7 | - Dotfiles 8 | - Updating 9 | - Installers 10 | - Commands 11 | - Generating 12 | - Next Steps 13 | 14 | Lets get started! 15 | 16 | ## Installation 17 | Installing dotman is as simple as running the following command: 18 | 19 | ```bash 20 | $ curl -L https://git.io/J68cu | bash 21 | ``` 22 | or 23 | ```bash 24 | $ curl https://raw.githubusercontent.com/d3r1n/dotman/master/linux_installer.sh | bash 25 | ``` 26 | 27 | What this command does is download the latest version of dotman's auto installer and run it. \ 28 | 29 | ## Dotfiles 30 | Dotfiles are files that are used to store configuration information. \ 31 | Dotfiles are usually stored in the `.config` directory in your home directory but they can be anywhere. \ 32 | With dotfiles you can configure your system in a way you can constumize anthing and maintain. \ 33 | 34 | But maintaing dotfiles is not easy. \ 35 | You have to know what files you want to store and where. \ 36 | That's why dotman is here to help you. 37 | 38 | ### Initializing 39 | we will be using a github repo to store our dotfiles. \ 40 | To initialize dotman you need to run the following command: 41 | 42 | ```bash 43 | $ mkdir MyDotfiles 44 | $ dotman init MyDotfiles --git --remote="https://github.com/YOUR_USERNAME/YOUR_REPO" --branch="master" 45 | ``` 46 | 47 | this command will initialize dotman in your current working directory. 48 | 49 | ### Adding Dotfiles 50 | To add dotfiles you need to have a file to add... :D \ 51 | So lets create a file called `.bashrc` and add it to the dotfiles repo: 52 | 53 | ```bash 54 | $ touch .bashrc 55 | $ echo "echo Hello World!" > .bashrc 56 | ``` 57 | 58 | Now we can add this file to the dotfiles repo: 59 | 60 | ```bash 61 | $ dotman add my_bashrc .bashrc --description="My bashrc file" 62 | ``` 63 | 64 | You can see 2 things are generated: 65 | - A new folder and file, `files/.bashrc` 66 | - A new dotfile object in `dotman.json` 67 | 68 | these files are used to store the dotfile. \ 69 | Yes! dotman does not uses symlinks to store dotfiles. \ 70 | It makes it easier to manage dotfiles and features. 71 | 72 | ## Updating 73 | Let's change something on our .bashrc file: 74 | ``bash 75 | $ echo "echo Hello From dotman!" > .bashrc 76 | ``` 77 | 78 | You can see that the file has changed. \ 79 | but our dotfile has not. 80 | 81 | We can update our dotfile using the following command: 82 | ```bash 83 | $ dotman update my_bashrc 84 | ``` 85 | 86 | Now everything is up-to-date. 87 | 88 | ## Installers 89 | With dotman you can create installers to install dotfiles. \ 90 | You can create installers to install dotfiles from a git repo, \ 91 | You can do anything you want with installers. \ 92 | They are basically automaticly generated bash scripts that will install dotfiles and run your custom commands. 93 | 94 | We will create an basic installer that installs our dotfiles: 95 | 96 | ```bash 97 | $ dotman installer add my_installer --description="My installer" 98 | ``` 99 | 100 | ## Commands 101 | 102 | This command will create a new installer called `my_installer` and add it to `dotman.json`. \ 103 | But it does not have any custom commands. \ 104 | So why not add some? 105 | 106 | ```bash 107 | $ dotman command add "echo I'm Pickle Riiiick!!" 108 | ``` 109 | 110 | ## Generating 111 | 112 | We added a dotfile, \ 113 | an installer, \ 114 | and a command. \ 115 | Now we need to generate the installer. 116 | 117 | In dotman installers will generate in the `installers` directory. \ 118 | with their own unique name: `installer[my_installer].sh` 119 | 120 | So let's generate the installer: 121 | ```bash 122 | $ dotman generate my_installer 123 | ``` 124 | 125 | Tada...! You created your own dot with dotman! \ 126 | and you can use it to install dotfiles. 127 | 128 | ## Next Steps 129 | You can learn more about dotman with reading the commands documentation. \ 130 | You can also learn more about dotman by reading the [documentation](commands) 131 | -------------------------------------------------------------------------------- /docs/commands.md: -------------------------------------------------------------------------------- 1 | # Documentation for commands 2 | 3 | ## **dotman init** 4 | ### *Description:* 5 | Initialize a dotman project. \ 6 | Automatically creates a `dotman.json` file in the current directory. \ 7 | If you already have a `dotman.json` file, it will be overwritten. 8 | 9 | ### *Usage:* 10 | ```bash 11 | dotman init [options] 12 | ``` 13 | 14 | ### *Options:* 15 | ```bash 16 | help: 17 | description: Show help information 18 | alias: none 19 | type: boolean 20 | default: false 21 | ``` 22 | 23 | ```bash 24 | name: 25 | description: The name of the project 26 | type: string 27 | required: true 28 | ``` 29 | 30 | ```bash 31 | --description:, -d: 32 | description: A description: of the project 33 | alias: -d 34 | type: string 35 | default: "No description: provided." 36 | ``` 37 | 38 | ```bash 39 | --install_path, -i: 40 | description: The location to install the project 41 | alias: -i 42 | type: string 43 | default: none 44 | ``` 45 | 46 | ```bash 47 | --git, -g: 48 | description: Initialize a git repository 49 | alias: -g 50 | type: boolean 51 | default: false 52 | ``` 53 | 54 | ```bash 55 | --remote, -r: 56 | description: The remote url of the git repository 57 | alias: -r 58 | type: string 59 | default: none 60 | ``` 61 | 62 | ```bash 63 | --branch, -b: 64 | description:*The branch name of the git repository 65 | alias: -b 66 | type: string 67 | default: none 68 | ``` 69 | --- 70 | 71 | ## **dotman add** 72 | ### *Description:* 73 | Add a dotfile to the project. 74 | 75 | 76 | ### *Usage:* 77 | ```bash 78 | dotman add [options] 79 | ``` 80 | 81 | ### *Options:* 82 | 83 | ```bash 84 | name: 85 | description The name of the dotfile 86 | type: string 87 | required: true 88 | ``` 89 | 90 | ```bash 91 | path: 92 | description: The path to the dotfile 93 | type: string 94 | required: true 95 | ``` 96 | 97 | ```bash 98 | --description, -d: 99 | description: A description of the project 100 | alias: -d 101 | type: string 102 | default: "No description provided." 103 | ``` 104 | 105 | ```bash 106 | --priority, -p: 107 | description The priority of the dotfile 108 | alias: -p 109 | type: integer 110 | default: 0 111 | ``` 112 | --- 113 | 114 | ## **dotman remove** 115 | ### *Description:* 116 | Remove a dotfile from the project. 117 | 118 | 119 | ### *Usage:* 120 | ```bash 121 | dotman remove 122 | ``` 123 | 124 | ### *Options:* 125 | 126 | ```bash 127 | name: 128 | description: The name of the dotfile to be removed 129 | type: string 130 | required: true 131 | ``` 132 | --- 133 | 134 | ## **dotman update** 135 | ### *Description:* 136 | Update a dotfile from the project. 137 | 138 | 139 | ### *Usage:* 140 | ```bash 141 | dotman update 142 | ``` 143 | 144 | ### *Options:* 145 | 146 | ```bash 147 | name: 148 | description: The name of the dotfile to be updated 149 | type: string 150 | required: true 151 | ``` 152 | 153 | ### *Special Usage:* 154 | ```bash 155 | dotman update @a 156 | ``` 157 | This usage will update all dotfiles. 158 | 159 | --- 160 | 161 | ## **dotman installer** 162 | ### *Description:* 163 | Installer Utilities. 164 | 165 | ### *Usage:* 166 | ```bash 167 | dotman installer [options] 168 | ``` 169 | 170 | ### *Method:* 171 | ```bash 172 | add: 173 | description: Add an installer to the project 174 | 175 | name: 176 | description: The name of the installer to be added 177 | type: string 178 | required: true 179 | ``` 180 | ```bash 181 | remove: 182 | description: Remove an installer from the project 183 | 184 | name: 185 | description: The name of the installer to be removed 186 | type: string 187 | required: true 188 | ``` 189 | 190 | ### *Options:* 191 | 192 | ```bash 193 | --description, -d: 194 | description: A description of the project 195 | alias: -d 196 | type: string 197 | default: "No description provided." 198 | ``` 199 | --- 200 | 201 | ## **dotman command** 202 | ### *Description:* 203 | Command Utilities. 204 | 205 | 206 | ### *Usage:* 207 | ```bash 208 | dotman command [options] 209 | ``` 210 | 211 | ### *Method:* 212 | ```bash 213 | add: 214 | description: Add a command to the project 215 | 216 | name: 217 | description: The name of the command to be added 218 | type: string 219 | required: true 220 | 221 | command: 222 | description: actual command to be run 223 | type: string 224 | required: true 225 | ``` 226 | ```bash 227 | remove: 228 | description: Remove a command from the project 229 | 230 | name: 231 | description: The name of the command to be removed 232 | type: string 233 | required: true 234 | ``` 235 | 236 | ### *Options:* 237 | 238 | ```bash 239 | --sudo, -s: 240 | description: Whether the command should be run with sudo 241 | alias: -s 242 | type: boolean 243 | default: false 244 | ``` 245 | --- 246 | 247 | ## **dotman generate** 248 | ### *Description:* 249 | Generate installer scripts. 250 | 251 | 252 | ### *Usage:* 253 | ```bash 254 | dotman generate 255 | ``` 256 | 257 | ### *Installer Name:* 258 | ```bash 259 | name of an installer defined in the project. 260 | ``` 261 | --- 262 | 263 | ## **dotman status** 264 | ### *Description:* 265 | Show the status of the project. 266 | 267 | 268 | ### *Usage:* 269 | ```bash 270 | dotman status 271 | ``` 272 | 273 | ### *Type:* 274 | 275 | ```bash 276 | normal: 277 | description: show basic indformation about the project 278 | ``` 279 | 280 | ```bash 281 | dotfiles: 282 | description: show extended indformation about the projects dotfiles 283 | ``` 284 | 285 | ```bash 286 | installers: 287 | description: show basic indformation about the projects installers 288 | ``` 289 | --- -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /utils.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "bytes" 6 | "encoding/json" 7 | "fmt" 8 | "io/ioutil" 9 | "os" 10 | "os/exec" 11 | "path/filepath" 12 | "strconv" 13 | "text/template" 14 | "time" 15 | 16 | "github.com/5elenay/ezcli" 17 | "github.com/fatih/color" 18 | "github.com/tidwall/pretty" 19 | ) 20 | 21 | /* ==== Globals ==== */ 22 | 23 | // colored output 24 | var ( 25 | red = color.New(color.FgHiRed) 26 | green = color.New(color.FgHiGreen) 27 | blue = color.New(color.FgHiCyan).Add(color.Bold) 28 | white = color.New(color.FgHiWhite).Add(color.Bold) 29 | yellow = color.New(color.FgHiYellow) 30 | ) 31 | 32 | // Formatted time.Now() 33 | var time_now = time.Now().Format("3:4:5 PM 2006-01-02") 34 | 35 | /* ================ */ 36 | 37 | /* === FUNCTIONS === */ 38 | 39 | // check if error is not nil 40 | func check_Error(err error) { 41 | if err != nil { 42 | panic(err) 43 | } 44 | } 45 | 46 | // check the file type of given file 47 | func check_File_Type(path string) string { 48 | fileInfo, err := os.Stat(path) 49 | check_Error(err) 50 | 51 | if fileInfo.IsDir() { 52 | return "directory" 53 | } else { 54 | return "file" 55 | } 56 | } 57 | 58 | // go does not have a built in array remove function / method WTF?!?!?!?!?!? 59 | func removeDotfileArray(slice []Dotfile, s int) []Dotfile { 60 | return append(slice[:s], slice[s+1:]...) 61 | } 62 | 63 | func removeInstallerArray(slice []Installer, s int) []Installer { 64 | return append(slice[:s], slice[s+1:]...) 65 | } 66 | 67 | func removeCommandArray(slice []Command, s int) []Command { 68 | return append(slice[:s], slice[s+1:]...) 69 | } 70 | 71 | /* === Generators === */ 72 | 73 | // Generate a new Config struct. 74 | func newConfig(Name string, Description string, InstallPath string, Git bool, Repository GitConfig, Dotfiles []Dotfile, Installers []Installer) *Config { 75 | return &Config{ 76 | Name: Name, 77 | Description: Description, 78 | InstallPath: InstallPath, 79 | Git: Git, 80 | Repository: Repository, 81 | Dotfiles: Dotfiles, 82 | Installers: Installers, 83 | } 84 | } 85 | 86 | // Generate a new Dotfile struct. 87 | func newDotfile(Name string, Description string, Location string, Type string, Priority int64, LastUpdate string) *Dotfile { 88 | return &Dotfile{ 89 | Name: Name, 90 | Description: Description, 91 | Location: Location, 92 | Type: Type, 93 | Priority: Priority, 94 | LastUpdate: LastUpdate, 95 | } 96 | } 97 | 98 | // Generate a new GitConfig struct. 99 | func newGitConfig(RemoteName string, Branch string, RemoteUrl string) *GitConfig { 100 | return &GitConfig{ 101 | RemoteName: RemoteName, 102 | Branch: Branch, 103 | RemoteUrl: RemoteUrl, 104 | } 105 | } 106 | 107 | // Generate a new Installer struct 108 | func newInstaller(Name string, Description string, Commands []Command) *Installer { 109 | return &Installer{ 110 | Name: Name, 111 | Description: Description, 112 | Commands: Commands, 113 | } 114 | } 115 | 116 | // Generate a new Command struct 117 | func newCommand(Execute string, Sudo bool) *Command { 118 | return &Command{ 119 | Execute: Execute, 120 | Sudo: Sudo, 121 | } 122 | } 123 | 124 | /* ================ */ 125 | 126 | // Convert Dotfile struct to JSON Representation 127 | func to_JSON(d Config) []byte { 128 | out, _ := json.Marshal(d) 129 | out = pretty.Pretty(out) 130 | return out 131 | } 132 | 133 | // Convert JSON Representation to Dotfile struct 134 | func from_JSON(JSON []byte) Config { 135 | var config Config 136 | err := json.Unmarshal(JSON, &config) 137 | check_Error(err) 138 | return config 139 | } 140 | 141 | // Generate JSON File 142 | func CreateAndWrite_JSON(input []byte) { 143 | file, err := os.Create("./dotman.json") 144 | check_Error(err) 145 | 146 | writer := bufio.NewWriter(file) 147 | 148 | wBytes, err := writer.Write(input) 149 | check_Error(err) 150 | 151 | _ = wBytes 152 | 153 | writer.Flush() 154 | file.Close() 155 | } 156 | 157 | // Check if dotman.json exists in the current working directory 158 | func check_config_exist() bool { 159 | if _, err := os.Stat("./dotman.json"); os.IsNotExist(err) { 160 | return false 161 | } else { 162 | return true 163 | } 164 | } 165 | 166 | func check_install_path_exist() bool { 167 | conf := read_config_file() 168 | 169 | if conf.InstallPath == "" { 170 | return false 171 | } else { 172 | return true 173 | } 174 | } 175 | 176 | // check if path exists 177 | func exists(path string) bool { 178 | if _, err := os.Stat(path); os.IsNotExist(err) { 179 | return false 180 | } else { 181 | return true 182 | } 183 | } 184 | 185 | // read the dotman.json config file 186 | func read_config_file() Config { 187 | file_contents, err := ioutil.ReadFile("dotman.json") 188 | check_Error(err) 189 | 190 | conf := from_JSON(file_contents) 191 | return conf 192 | } 193 | 194 | // Add Dotfile struct to the dotman.json file 195 | func add_dotfile(d Dotfile) { 196 | file, err := os.OpenFile("dotman.json", os.O_CREATE|os.O_RDWR, 0644) 197 | check_Error(err) 198 | 199 | conf := read_config_file() 200 | 201 | // Check if the dotfile is already declared 202 | for i := 0; i < len(conf.Dotfiles); i++ { 203 | if d.Name == conf.Dotfiles[i].Name { 204 | red.Printf("\"%s\" already exists in dotman.json\n", d.Name) 205 | os.Exit(1) 206 | } 207 | } 208 | 209 | conf.Dotfiles = append(conf.Dotfiles, d) 210 | 211 | wBytes, err := file.Write(to_JSON(conf)) 212 | check_Error(err) 213 | 214 | _ = wBytes 215 | 216 | err = file.Sync() 217 | check_Error(err) 218 | err = file.Close() 219 | check_Error(err) 220 | } 221 | 222 | // Remove Dotfile struct from the dotman.json file 223 | func remove_dotfile(name string) []string { 224 | file, err := os.OpenFile("dotman.json", os.O_WRONLY, 6666) 225 | check_Error(err) 226 | 227 | conf := read_config_file() 228 | 229 | // if dotfile is exists set isFound to true and Remove the Dotfile struct from the array 230 | // otherwise set isFound to false and continue until whole loop is finished 231 | var isFound bool 232 | var Found Dotfile 233 | for index, obj := range conf.Dotfiles { 234 | if obj.Name == name { 235 | green.Printf("Found \"%s\" DotFile\n", obj.Name) 236 | blue.Println("Removing...") 237 | isFound = true 238 | Found = obj 239 | conf.Dotfiles = removeDotfileArray(conf.Dotfiles, index) 240 | break 241 | } else { 242 | isFound = false 243 | continue 244 | } 245 | } 246 | 247 | if !isFound { 248 | red.Printf("Can't find \"%s\" in dotman.json", name) 249 | os.Exit(1) 250 | 251 | return []string{} 252 | } else { 253 | err_ := os.Truncate("dotman.json", 0) 254 | check_Error(err_) 255 | 256 | writer := bufio.NewWriter(file) 257 | _, err := writer.Write(to_JSON(conf)) 258 | check_Error(err) 259 | 260 | writer.Flush() 261 | file.Close() 262 | 263 | return []string{Found.Location, Found.Type} 264 | } 265 | } 266 | 267 | // Update a Dotfile struct in the dotman.json file 268 | func update_dotfile(name string) string { 269 | file, err := os.OpenFile("dotman.json", os.O_WRONLY, 6666) 270 | check_Error(err) 271 | 272 | conf := read_config_file() 273 | 274 | // if dotfile is exists set isFound to true and Update the Dotfile struct from the array 275 | // otherwise set isFound to false and continue until whole loop is finished 276 | var isFound bool 277 | var Location string 278 | for _, obj := range conf.Dotfiles { 279 | if obj.Name == name { 280 | green.Printf("\nFound \"%s\" DotFile\n", obj.Name) 281 | blue.Println("Updating...\n") 282 | isFound = true 283 | Location = obj.Location 284 | obj.LastUpdate = time_now 285 | copyFileOrDir(obj.Location, FILES_PATH) 286 | break 287 | } else { 288 | isFound = false 289 | continue 290 | } 291 | } 292 | 293 | if !isFound { 294 | red.Printf("Can't find \"%s\" in dotman.json", name) 295 | os.Exit(1) 296 | 297 | return "" 298 | } else { 299 | err_ := os.Truncate("dotman.json", 0) 300 | check_Error(err_) 301 | 302 | writer := bufio.NewWriter(file) 303 | _, err := writer.Write(to_JSON(conf)) 304 | check_Error(err) 305 | 306 | writer.Flush() 307 | file.Close() 308 | 309 | // git stuff 310 | git_add(FILES_PATH + filepath.Base(Location)) 311 | git_commit(fmt.Sprintf("Dotman: Updated the \"%s\" dotfile | "+time_now, name)) 312 | git_push(conf.Repository.RemoteName, conf.Repository.Branch) 313 | 314 | return Location 315 | } 316 | } 317 | 318 | // Update all the Dotfile structs in the dotman.json file 319 | func update_all_dotfiles() { 320 | file, err := os.OpenFile("dotman.json", os.O_WRONLY, 6666) 321 | check_Error(err) 322 | 323 | conf := read_config_file() 324 | 325 | green.Printf("\nFound %d dotfiles in dotman.json\n", len(conf.Dotfiles)) 326 | 327 | // iterate over all the dotfiles and updae them 328 | for index, obj := range conf.Dotfiles { 329 | blue.Printf("Updating: %s...\n", obj.Name) 330 | conf.Dotfiles[index].LastUpdate = time_now 331 | copyFileOrDir(obj.Location, FILES_PATH) 332 | 333 | git_add(FILES_PATH + filepath.Base(obj.Location)) 334 | } 335 | 336 | // git stuff 337 | git_commit("Dotman: Updated all the dotfiles. | " + time_now) 338 | git_push(conf.Repository.RemoteName, conf.Repository.Branch) 339 | 340 | err_ := os.Truncate("dotman.json", 0) 341 | check_Error(err_) 342 | 343 | writer := bufio.NewWriter(file) 344 | out, err := writer.Write(to_JSON(conf)) 345 | check_Error(err) 346 | _ = out 347 | 348 | writer.Flush() 349 | file.Close() 350 | } 351 | 352 | // === Installer Functions === 353 | 354 | // add a new installer to the installers in dotman.json 355 | func add_installer(ins Installer) { 356 | file, err := os.OpenFile("dotman.json", os.O_WRONLY, 6666) 357 | check_Error(err) 358 | 359 | conf := read_config_file() 360 | 361 | // check if the installer is already declared 362 | for _, obj := range conf.Installers { 363 | if ins.Name == obj.Name { 364 | red.Printf("Installer \"%s\" already exists in dotman.json\n", ins.Name) 365 | os.Exit(1) 366 | } 367 | } 368 | 369 | conf.Installers = append(conf.Installers, ins) 370 | 371 | wBytes, err := file.Write(to_JSON(conf)) 372 | check_Error(err) 373 | 374 | _ = wBytes 375 | 376 | err = file.Sync() 377 | check_Error(err) 378 | err = file.Close() 379 | check_Error(err) 380 | } 381 | 382 | // remove an installer from the installers in dotman.json 383 | func remove_installer(name string) { 384 | file, err := os.OpenFile("dotman.json", os.O_WRONLY, 6666) 385 | check_Error(err) 386 | 387 | conf := read_config_file() 388 | 389 | // if installer is exists set isFound to true and Remove the Installer struct from the array 390 | // otherwise set isFound to false and continue until whole loop is finished 391 | var isFound bool 392 | for index, obj := range conf.Installers { 393 | if obj.Name == name { 394 | green.Printf("Found \"%s\" DotFile\n", obj.Name) 395 | blue.Println("Removing...") 396 | isFound = true 397 | conf.Installers = removeInstallerArray(conf.Installers, index) 398 | break 399 | } else { 400 | isFound = false 401 | continue 402 | } 403 | } 404 | 405 | if !isFound { 406 | red.Printf("Can't find \"%s\" in dotman.json", name) 407 | os.Exit(1) 408 | } else { 409 | err_ := os.Truncate("dotman.json", 0) 410 | check_Error(err_) 411 | writer := bufio.NewWriter(file) 412 | _, err := writer.Write(to_JSON(conf)) 413 | check_Error(err) 414 | 415 | writer.Flush() 416 | file.Close() 417 | } 418 | } 419 | 420 | // Generate installer Bash File 421 | func CreateInstallerScript(name string, input []byte) { 422 | file, err := os.Create(INSTALLERS_PATH + "installer[" + name + "].sh") 423 | check_Error(err) 424 | 425 | writer := bufio.NewWriter(file) 426 | 427 | wBytes, err := writer.Write(input) 428 | check_Error(err) 429 | 430 | _ = wBytes 431 | 432 | writer.Flush() 433 | file.Close() 434 | } 435 | 436 | // add a new command to a specific installer 437 | func add_command(name string, c Command) { 438 | file, err := os.OpenFile("dotman.json", os.O_CREATE|os.O_RDWR, 0644) 439 | check_Error(err) 440 | 441 | conf := read_config_file() 442 | 443 | // if Installer is exists set isFound to true and add a new command to the Installer.Commands array 444 | // otherwise set isFound to false and continue until whole loop is finished 445 | var isFound bool 446 | var indx int 447 | for index, obj := range conf.Installers { 448 | if obj.Name == name { 449 | green.Printf("Found \"%s\" Installer\n", obj.Name) 450 | blue.Println("Adding...") 451 | isFound = true 452 | conf.Installers[index].Commands = append(conf.Installers[index].Commands, c) 453 | indx = index 454 | break 455 | } else { 456 | isFound = false 457 | continue 458 | } 459 | } 460 | 461 | if !isFound { 462 | red.Printf("Can't find Installer \"%s\" in dotman.json", name) 463 | os.Exit(1) 464 | } else { 465 | err_ := os.Truncate("dotman.json", 0) 466 | check_Error(err_) 467 | 468 | writer := bufio.NewWriter(file) 469 | _, err := writer.Write(to_JSON(conf)) 470 | check_Error(err) 471 | 472 | writer.Flush() 473 | file.Close() 474 | } 475 | 476 | // git stuff 477 | gitAdd("./dotman.json", "Dotman: Added 1 Command to "+conf.Installers[indx].Name, conf.Repository.RemoteName, conf.Repository.Branch) 478 | } 479 | 480 | // remove a command from a specific installer 481 | func remove_command(name string, command string) { 482 | file, err := os.OpenFile("dotman.json", os.O_CREATE|os.O_RDWR, 0644) 483 | check_Error(err) 484 | 485 | conf := read_config_file() 486 | 487 | // if command is exists set isFound to true and remove the command from the Installer.Commands array 488 | // otherwise set isFound to false and continue until whole loop is finished 489 | var isFound bool 490 | var indx int 491 | for index, obj := range conf.Installers { 492 | if obj.Name == name { 493 | green.Printf("Found \"%s\" Installer\n", obj.Name) 494 | 495 | for i, o := range conf.Installers[index].Commands { 496 | if o.Execute == command { 497 | green.Printf("Found \"%s\" Command\n", o.Execute) 498 | blue.Println("Removing...") 499 | conf.Installers[index].Commands = removeCommandArray(conf.Installers[index].Commands, i) 500 | isFound = true 501 | break 502 | } else { 503 | isFound = false 504 | continue 505 | } 506 | } 507 | 508 | indx = index 509 | break 510 | } 511 | } 512 | 513 | if !isFound { 514 | red.Printf("Can't find Command \"%s\" in Installer \"%s\" dotman.json", command, name) 515 | os.Exit(1) 516 | } else { 517 | err_ := os.Truncate("dotman.json", 0) 518 | check_Error(err_) 519 | 520 | writer := bufio.NewWriter(file) 521 | _, err := writer.Write(to_JSON(conf)) 522 | check_Error(err) 523 | 524 | writer.Flush() 525 | file.Close() 526 | } 527 | 528 | // git stuff 529 | gitAdd("./dotman.json", "Dotman: Added 1 Command to "+conf.Installers[indx].Name, conf.Repository.RemoteName, conf.Repository.Branch) 530 | } 531 | 532 | // Generate a new bash script for a specific installer 533 | func generate_installer(name string) { 534 | file, err := os.OpenFile("dotman.json", os.O_WRONLY, 6666) 535 | check_Error(err) 536 | 537 | conf := read_config_file() 538 | 539 | if !exists(INSTALLERS_PATH) { 540 | err := os.Mkdir(INSTALLERS_PATH, 0777) 541 | check_Error(err) 542 | } 543 | 544 | // if installer is exists set isFound to true and generate a new bash script 545 | // otherwise set isFound to false and continue until whole loop is finished 546 | var isFound bool 547 | for index, obj := range conf.Installers { 548 | if obj.Name == name { 549 | isFound = true 550 | 551 | var parsed_byte bytes.Buffer 552 | conf := read_config_file() 553 | 554 | tmpl := template.Must(template.New("installer").Parse(installer_template)) 555 | 556 | err := tmpl.Execute(&parsed_byte, Tmpl{ 557 | InstallPath: conf.InstallPath, 558 | Installer: conf.Installers[index], 559 | }) 560 | 561 | check_Error(err) 562 | 563 | CreateInstallerScript(name, parsed_byte.Bytes()) 564 | 565 | break 566 | } else { 567 | isFound = false 568 | continue 569 | } 570 | } 571 | 572 | if !isFound { 573 | red.Printf("Can't find Installer \"%s\" in dotman.json", name) 574 | os.Exit(1) 575 | } else { 576 | // Remove All the contents of the dotman.json file 577 | err_ := os.Truncate("dotman.json", 0) 578 | check_Error(err_) 579 | 580 | // new buffer writer for the file 581 | writer := bufio.NewWriter(file) 582 | _, err := writer.Write(to_JSON(conf)) 583 | check_Error(err) 584 | 585 | // flush the io writer and close the file 586 | writer.Flush() 587 | file.Close() 588 | } 589 | 590 | gitAdd(INSTALLERS_PATH+"installer["+name+"].sh", "Dotman: Generated Installer Script ["+name+"]", conf.Repository.RemoteName, conf.Repository.Branch) 591 | } 592 | 593 | // Show the status of the dotman.json file 594 | func show_status(option string) { 595 | conf := read_config_file() 596 | 597 | // show basic info 598 | if option == "normal" { 599 | 600 | color.New(color.FgHiCyan).Add(color.Bold).Add(color.Italic).Add(color.Italic).Printf("\n\n+-- Dotman Status --+\n") 601 | fmt.Printf("\n") 602 | 603 | white.Printf("%s", "Name: ") 604 | color.New(color.FgHiMagenta).Printf("%s\n", conf.Name) 605 | 606 | white.Printf("%s", "Description: ") 607 | yellow.Printf("\"%s\"\n", conf.Description) 608 | 609 | white.Printf("%s", "Install Path: ") 610 | yellow.Printf("%s\n", conf.InstallPath) 611 | 612 | white.Printf("%s", "Git Enabled? ") 613 | color.New(color.FgHiMagenta).Printf("%t\n", conf.Git) 614 | 615 | white.Printf("\n%s\n", "Repository\n+--------+") 616 | 617 | white.Printf("* %s", "Name: ") 618 | yellow.Printf("%s\n", conf.Repository.RemoteName) 619 | white.Printf("* %s", "Branch: ") 620 | yellow.Printf("%s\n", conf.Repository.Branch) 621 | white.Printf("* %s", "URL: ") 622 | yellow.Printf("%s\n", conf.Repository.RemoteUrl) 623 | white.Printf("+--------+") 624 | 625 | white.Printf("\n\n%s", "Dotfiles: ") 626 | green.Printf("%d Dotfiles in this dot.\n", len(conf.Dotfiles)) 627 | 628 | white.Printf("%s", "Installers: ") 629 | green.Printf("%d Custom installers in this dot.\n\n", len(conf.Installers)) 630 | 631 | color.New(color.FgHiCyan).Add(color.Bold).Printf("+-------------------+\n") 632 | 633 | // show detailed info about dotfiles 634 | } else if option == "dotfiles" { 635 | 636 | color.New(color.FgHiCyan).Add(color.Bold).Add(color.Italic).Add(color.Italic).Printf("\n\n+-- Dotman Dotfiles --+\n") 637 | fmt.Printf("\n") 638 | 639 | for _, obj := range conf.Dotfiles { 640 | red.Add(color.Bold).Add(color.Italic).Add(color.Italic).Printf("+-------------+\n") 641 | 642 | white.Printf("Name: ") 643 | yellow.Printf("%s\n", obj.Name) 644 | 645 | white.Printf("Description: ") 646 | yellow.Printf("%s\n", obj.Description) 647 | 648 | white.Printf("Location: ") 649 | yellow.Printf("%s\n", obj.Location) 650 | 651 | white.Printf("Type: ") 652 | yellow.Printf("%s\n", obj.Type) 653 | 654 | white.Printf("Priority: ") 655 | yellow.Printf("%d\n", obj.Priority) 656 | 657 | white.Printf("Last Update: ") 658 | yellow.Printf("%s\n", obj.LastUpdate) 659 | 660 | red.Add(color.Bold).Add(color.Italic).Add(color.Italic).Printf("+-------------+\n\n") 661 | } 662 | 663 | color.New(color.FgHiCyan).Add(color.Bold).Printf("+-------------------+\n") 664 | 665 | // show detailed info about installers 666 | } else if option == "installers" { 667 | color.New(color.FgHiCyan).Add(color.Bold).Add(color.Italic).Add(color.Italic).Printf("\n\n+-- Dotman Commands --+\n") 668 | fmt.Printf("\n") 669 | 670 | for _, obj := range conf.Installers { 671 | red.Add(color.Bold).Add(color.Italic).Add(color.Italic).Printf("+-------------+\n") 672 | 673 | white.Printf("Installer: ") 674 | yellow.Printf("%s\n", obj.Name) 675 | 676 | white.Printf("Description: ") 677 | yellow.Printf("%s\n", obj.Description) 678 | 679 | white.Printf("\nCommands:\n+--------+\n") 680 | 681 | for i, cmd := range obj.Commands { 682 | white.Printf("* Command: %s\n", color.HiYellowString(cmd.Execute)) 683 | white.Printf("* Is Sudo? %s\n", color.HiMagentaString(strconv.FormatBool(cmd.Sudo))) 684 | if i != len(obj.Commands)-1 { 685 | white.Printf("+--------+\n") 686 | } 687 | } 688 | 689 | white.Printf("+--------+\n") 690 | 691 | red.Add(color.Bold).Add(color.Italic).Add(color.Italic).Printf("+-------------+\n\n") 692 | } 693 | 694 | color.New(color.FgHiCyan).Add(color.Bold).Printf("+--------------------+\n") 695 | } 696 | } 697 | 698 | // File Utils: 699 | 700 | // Copy a file or a directory 701 | func copyFileOrDir(from_location string, to_location string) { 702 | cmd := exec.Command("cp", "-f", "-r", from_location, to_location) 703 | err := cmd.Run() 704 | check_Error(err) 705 | } 706 | 707 | // Delete a file or a directory 708 | func deleteFileOrDir(file string, file_type string) { 709 | if file_type == "file" { 710 | cmd := exec.Command("rm", file) 711 | cmd.Run() 712 | } else if file_type == "directory" { 713 | cmd := exec.Command("rm", "-d", file) 714 | err := cmd.Run() 715 | check_Error(err) 716 | } 717 | } 718 | 719 | /* ======================= */ 720 | 721 | /* ==== GIT UTILITIES ==== */ 722 | 723 | // git init 724 | func git_init() { 725 | cmd := exec.Command("git", "init") 726 | cmd.Run() 727 | } 728 | 729 | // git remote add 730 | func git_remote_add(name string, url string) { 731 | cmd := exec.Command("git", "remote", "add", name, url) 732 | cmd.Run() 733 | } 734 | 735 | func git_branch_add(name string) { 736 | cmd := exec.Command("git", "branch", "-M", name) 737 | cmd.Run() 738 | } 739 | 740 | // git add 741 | func git_add(path string) { 742 | cmd := exec.Command("git", "add", path) 743 | cmd.Run() 744 | } 745 | 746 | // git remove 747 | func git_remove(path string) { 748 | cmd := exec.Command("git", "rm", path, "--cached") 749 | cmd.Run() 750 | } 751 | 752 | // git commit 753 | func git_commit(message string) { 754 | cmd := exec.Command("git", "commit", "-m", message) 755 | cmd.Run() 756 | } 757 | 758 | // git checkout 759 | func git_checkout(branch string) { 760 | cmd := exec.Command("git", "checkout", branch) 761 | cmd.Run() 762 | } 763 | 764 | // check the current working branch 765 | /* func check_git_branch() string { 766 | cmd := exec.Command("git", "branch") 767 | out, err := cmd.Output() 768 | check_Error(err) 769 | return string(out) 770 | } */ 771 | 772 | // git push 773 | func git_push(remote string, branch string) { 774 | cmd := exec.Command("git", "push", remote, branch) 775 | cmd.Run() 776 | } 777 | 778 | // All in one commands: 779 | 780 | // add dotfile 781 | func gitAdd(add_path string, commit_message string, remote_name string, remote_branch string) { 782 | git_add(add_path) 783 | git_commit(commit_message) 784 | git_push(remote_name, remote_branch) 785 | } 786 | 787 | // remove dotfile 788 | func gitRemove(remove_path string, commit_message string, remote_name string, remote_branch string) { 789 | git_remove(remove_path) 790 | git_commit(commit_message) 791 | git_push(remote_name, remote_branch) 792 | } 793 | 794 | /* ======================= */ 795 | 796 | /* ==== Main Functions ==== */ 797 | 798 | func Init(c *ezcli.Command) { 799 | var conf Config 800 | 801 | var name string = "" 802 | var description string = "No description specified" 803 | var install_path string = "" 804 | var git bool = false 805 | var remote_url string 806 | var branch_name string 807 | 808 | var repository GitConfig 809 | var dotfiles []Dotfile = []Dotfile{} 810 | var installers []Installer = []Installer{} 811 | 812 | // Parse the positional argument "" 813 | for i, v := range c.CommandData.Arguments { 814 | switch i { 815 | case 0: 816 | name = v 817 | } 818 | } 819 | 820 | // Wrong usage output 821 | if name == "" { 822 | red.Println("Please input the \"Name\" of the Dotman Project.") 823 | os.Exit(1) 824 | } 825 | 826 | for _, option := range c.CommandData.Options { 827 | switch option.Name { 828 | case "description": 829 | description = option.Value 830 | 831 | case "install_path": 832 | install_path = option.Value 833 | 834 | case "git": 835 | git = true 836 | 837 | case "remote": 838 | remote_url = option.Value 839 | 840 | case "branch": 841 | branch_name = option.Value 842 | } 843 | } 844 | 845 | // if "git" is set and if remote url and branch name set too, new GitConfig struct will be created 846 | if git { 847 | if remote_url != "" && branch_name != "" { 848 | repository = *newGitConfig("origin", branch_name, remote_url) 849 | blue.Println("Git Enabled.\n") 850 | } else { 851 | red.Println("Please set both the Branch name and the Remote URL to use git repositories!\n") 852 | os.Exit(1) 853 | } 854 | } 855 | 856 | conf = *newConfig(name, description, install_path, git, repository, dotfiles, installers) 857 | json := to_JSON(conf) 858 | CreateAndWrite_JSON(json) 859 | 860 | // git stuff 861 | git_init() 862 | git_add("./dotman.json") 863 | git_commit("Dotman: Initialized Repository") 864 | git_branch_add(branch_name) 865 | git_checkout(branch_name) 866 | git_remote_add("origin", remote_url) 867 | git_push("origin", branch_name) 868 | 869 | green.Printf("Initialized Dotfile Project \"%s\" successfuly.", name) 870 | } 871 | 872 | func Add(c *ezcli.Command) { 873 | // check if dotman.json exists 874 | if !check_config_exist() { 875 | red.Println("Can't find the dotman.json file.") 876 | blue.Println("Run \"dotman init\" to initialize the configuration.") 877 | os.Exit(1) 878 | } 879 | 880 | var name string = "" 881 | var location string = "" 882 | var description string = "No description specified" 883 | var Type string = "" 884 | var priority int64 = 1 885 | var lastupdate string = time.Now().Format("3:4:5 PM 2006-01-02") 886 | 887 | // Parse the positional arguments "" and "" 888 | for i, v := range c.CommandData.Arguments { 889 | switch i { 890 | case 0: 891 | name = v 892 | 893 | case 1: 894 | location = v 895 | } 896 | } 897 | 898 | // Wrong usage output 899 | if name == "" || location == "" { 900 | red.Println("Please input the \"Name\" and \"Location\" of the Dotfile.") 901 | os.Exit(1) 902 | } else if name == "@a" { 903 | red.Println("\"@a\" is a special name. You cant use it!") 904 | os.Exit(1) 905 | } 906 | 907 | for _, option := range c.CommandData.Options { 908 | switch option.Name { 909 | case "description": 910 | description = option.Value 911 | 912 | // priority must be between or equal 1 and 3 913 | case "priority": 914 | if i, _ := strconv.ParseInt(option.Value, 0, 8); i > 3 { 915 | priority = 3 916 | } else if i, _ := strconv.ParseInt(option.Value, 0, 8); i < 0 { 917 | priority = 1 918 | } else { 919 | priority = 1 920 | } 921 | } 922 | } 923 | 924 | if !exists(location) { 925 | red.Println("The location you specified does not exist.") 926 | os.Exit(1) 927 | } 928 | 929 | // determine the type of the file being added 930 | if check_File_Type(location) == "file" { 931 | Type = "file" 932 | } else if check_File_Type(location) == "directory" { 933 | Type = "directory" 934 | } 935 | 936 | var inputDotfile Dotfile = *newDotfile(name, description, location, Type, priority, lastupdate) 937 | add_dotfile(inputDotfile) 938 | 939 | // if ./files/ exist then copy the file inside it, if not make a directory named ./files/ then copy the file inside it 940 | if exists(FILES_PATH) { 941 | copyFileOrDir(inputDotfile.Location, FILES_PATH) 942 | } else { 943 | err := os.Mkdir(FILES_PATH, os.FileMode(0755)) 944 | check_Error(err) 945 | copyFileOrDir(inputDotfile.Location, FILES_PATH) 946 | } 947 | 948 | conf := read_config_file() 949 | 950 | gitAdd(FILES_PATH+filepath.Base(inputDotfile.Location), fmt.Sprintf("Dotman: Added a \"%s\" dotfile | "+inputDotfile.LastUpdate, name), conf.Repository.RemoteName, conf.Repository.Branch) 951 | 952 | green.Printf("\nAdded \"%s\" to Dotfiles.\n", name) 953 | } 954 | 955 | func Remove(c *ezcli.Command) { 956 | // check if dotman.json exists 957 | if !check_config_exist() { 958 | red.Println("Can't find the dotman.json file.") 959 | blue.Println("Run \"dotman init\" to initialize the configuration.") 960 | os.Exit(1) 961 | } 962 | 963 | var name string = "" 964 | 965 | // Parse the positional argument "" 966 | for i, v := range c.CommandData.Arguments { 967 | switch i { 968 | case 0: 969 | name = v 970 | } 971 | } 972 | 973 | // Wrong usage output 974 | if name == "" { 975 | red.Println("Please input the \"Name\" of the Dotfile you want to remove.") 976 | os.Exit(1) 977 | } 978 | 979 | conf := read_config_file() 980 | 981 | // remove dotfile from dotman.json and return the Location of the removed Dotfile 982 | path := remove_dotfile(name) 983 | file_name := FILES_PATH + filepath.Base(path[0]) // just filename.extension 984 | 985 | gitRemove(file_name, fmt.Sprintf("Dotman: Removed the \"%s\" dotfile | "+time_now, name), conf.Repository.RemoteName, conf.Repository.Branch) // remove dotfile from git repository 986 | deleteFileOrDir(file_name, path[1]) // delete the file or directory dotfile linked to 987 | 988 | green.Printf("\"%s\" successfuly removed.\n", name) 989 | } 990 | 991 | func Update(c *ezcli.Command) { 992 | // check if dotman.json exists 993 | if !check_config_exist() { 994 | red.Println("Can't find the dotman.json file.") 995 | blue.Println("Run \"dotman init\" to initialize the configuration.") 996 | os.Exit(1) 997 | } 998 | 999 | var name string = "" 1000 | 1001 | // Parse the positional argument "" 1002 | for i, v := range c.CommandData.Arguments { 1003 | switch i { 1004 | case 0: 1005 | name = v 1006 | } 1007 | } 1008 | 1009 | // Wrong usage output 1010 | if name == "" { 1011 | red.Println("Please input the \"Name\" of the Dotfile you want to update.") 1012 | blue.Println("Use \"@a\" to update all the dotfiles.") 1013 | os.Exit(1) 1014 | } 1015 | 1016 | // Special handle named "@a" to update all the dotfiles || yes its inspired by minecraft :) 1017 | if name == "@a" { 1018 | update_all_dotfiles() 1019 | green.Println("\nSuccessfuly updated all the Dotfiles.") 1020 | } else { // otherwise update single dotfile 1021 | dotfile_path := update_dotfile(name) 1022 | copyFileOrDir(dotfile_path, FILES_PATH) 1023 | green.Printf("\"%s\" successfuly updated.\n", name) 1024 | } 1025 | } 1026 | 1027 | func CommandHandler(c *ezcli.Command) { 1028 | // check if dotman.json exists 1029 | if !check_config_exist() { 1030 | red.Println("Can't find the dotman.json file.") 1031 | blue.Println("Run \"dotman init\" to initialize the configuration.") 1032 | os.Exit(1) 1033 | } 1034 | 1035 | var method string = "" 1036 | 1037 | var name string = "" 1038 | var command string = "" 1039 | var sudo bool = false 1040 | 1041 | // Parse the positional arguments ", " and "" 1042 | for i, v := range c.CommandData.Arguments { 1043 | switch i { 1044 | case 0: 1045 | method = v 1046 | case 1: 1047 | name = v 1048 | case 2: 1049 | command = v 1050 | } 1051 | } 1052 | 1053 | for _, option := range c.CommandData.Options { 1054 | switch option.Name { 1055 | case "sudo": 1056 | sudo = true 1057 | } 1058 | } 1059 | 1060 | // Wrong usage output 1061 | if method == "" { 1062 | red.Println("Please input the method you want to use.") 1063 | blue.Println("Use \"add\" to add a command") 1064 | blue.Println("Use \"remove\" to remove a command") 1065 | os.Exit(1) 1066 | } else if method != "add" && method != "remove" { 1067 | red.Println("Invalid method!") 1068 | blue.Println("Use \"add\" to add a command") 1069 | blue.Println("Use \"remove\" to remove a command") 1070 | os.Exit(1) 1071 | } else if method == "add" && (name == "" || command == "") { 1072 | red.Println("Empty field(s)! Please input all the fields") 1073 | fmt.Printf("Try typing \"hello %s\"\n", color.CyanString("\"echo Hello World!\"")) 1074 | os.Exit(1) 1075 | } else if method == "remove" && (name == "" || command == "") { 1076 | red.Println("Empty field(s)! Please input all the fields") 1077 | os.Exit(1) 1078 | } 1079 | 1080 | if method == "add" { 1081 | 1082 | Command := newCommand(command, sudo) 1083 | 1084 | add_command(name, *Command) 1085 | green.Println("\nAdded " + name + " to Commands.") 1086 | 1087 | } else if method == "remove" { 1088 | remove_command(name, command) 1089 | green.Println("\nRemoved " + name + " from Commands.") 1090 | } 1091 | } 1092 | 1093 | func InstallerHandler(c *ezcli.Command) { 1094 | // check if dotman.json exists 1095 | if !check_config_exist() { 1096 | red.Println("Can't find the dotman.json file.") 1097 | blue.Println("Run \"dotman init\" to initialize the configuration.") 1098 | os.Exit(1) 1099 | } 1100 | 1101 | var method string = "" 1102 | 1103 | var name string = "" 1104 | var description string = "" 1105 | 1106 | // Parse the positional arguments " and " 1107 | for i, v := range c.CommandData.Arguments { 1108 | switch i { 1109 | case 0: 1110 | method = v 1111 | case 1: 1112 | name = v 1113 | } 1114 | } 1115 | 1116 | for _, option := range c.CommandData.Options { 1117 | switch option.Name { 1118 | case "description": 1119 | description = option.Value 1120 | } 1121 | } 1122 | 1123 | // Wrong usage output 1124 | if method == "" { 1125 | red.Println("Please input the method you want to use.") 1126 | blue.Println("Use \"add\" to add a command") 1127 | blue.Println("Use \"remove\" to remove a command") 1128 | os.Exit(1) 1129 | } else if method != "add" && method != "remove" { 1130 | red.Println("Invalid method!") 1131 | blue.Println("Use \"add\" to add a command") 1132 | blue.Println("Use \"remove\" to remove a command") 1133 | os.Exit(1) 1134 | } else if method == "add" && name == "" { 1135 | red.Println("Empty field(s)! Please input all the fields") 1136 | fmt.Printf("Try typing \"hello %s\"\n", color.CyanString("\"echo Hello World!\"")) 1137 | os.Exit(1) 1138 | } else if method == "remove" && name == "" { 1139 | red.Println("Empty field(s)! Please input all the fields") 1140 | os.Exit(1) 1141 | } 1142 | 1143 | if method == "add" { 1144 | 1145 | Instaler := newInstaller(name, description, []Command{}) 1146 | 1147 | add_installer(*Instaler) 1148 | green.Println("\nAdded " + name + " to Installer.") 1149 | 1150 | } else if method == "remove" { 1151 | remove_installer(name) 1152 | green.Println("\nRemoved " + name + " from Installers.") 1153 | } 1154 | } 1155 | 1156 | func Install(c *ezcli.Command) { 1157 | // check if dotman.json exists 1158 | if !check_config_exist() { 1159 | red.Println("Can't find the dotman.json file.") 1160 | blue.Println("Run \"dotman init\" to initialize the configuration.") 1161 | os.Exit(1) 1162 | } 1163 | 1164 | // check if installation path is specified 1165 | if !check_install_path_exist() { 1166 | red.Println("Can't find Installation Path in dotman.json file.") 1167 | blue.Println("Please initialize the Installation Path in the configuration.") 1168 | os.Exit(1) 1169 | } 1170 | 1171 | var name string = "" 1172 | 1173 | // Parse the positional arguments "" 1174 | for i, v := range c.CommandData.Arguments { 1175 | switch i { 1176 | case 0: 1177 | name = v 1178 | } 1179 | } 1180 | 1181 | // Wrong usage output 1182 | if name == "" { 1183 | red.Println("Please input the \"Name\" of the Installer you want to add.") 1184 | os.Exit(1) 1185 | } 1186 | 1187 | generate_installer(name) 1188 | 1189 | green.Println("\nGenerated Installer!") 1190 | blue.Println("\nPlease run following command to make installer usable:") 1191 | blue.Println("\tsudo chmod +x ./" + INSTALLERS_PATH + "installer[" + name + "].sh") 1192 | blue.Println("\nCheck out ./installer.sh") 1193 | } 1194 | 1195 | func Status(c *ezcli.Command) { 1196 | // check if dotman.json exists 1197 | if !check_config_exist() { 1198 | red.Println("Can't find the dotman.json file.") 1199 | blue.Println("Run \"dotman init\" to initialize the configuration.") 1200 | os.Exit(1) 1201 | } 1202 | 1203 | // variables ._. 1204 | var method string = "NULL" 1205 | 1206 | // Parse the positional arguments "" 1207 | for i, v := range c.CommandData.Arguments { 1208 | switch i { 1209 | case 0: 1210 | method = v 1211 | } 1212 | } 1213 | 1214 | // Wrong usage output 1215 | if method != "normal" && method != "dotfiles" && method != "installers" && method != "NULL" { 1216 | red.Printf("\"%s\" is not a valid command.", method) 1217 | white.Println("\n\nCommands:") 1218 | blue.Println("\tnormal | display general information about dot.") 1219 | blue.Println("\tdotfiles | display information about dotfiles in dot.") 1220 | blue.Println("\tinstallers | display information about installers in dot") 1221 | os.Exit(1) 1222 | } else if method == "NULL" { 1223 | show_status("normal") 1224 | } else { 1225 | show_status(method) 1226 | } 1227 | } 1228 | 1229 | /* ======================= */ 1230 | --------------------------------------------------------------------------------