Skip to content

Commit

Permalink
Merge branch 'release/0.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
jjzcru committed May 4, 2020
2 parents 13828dc + 277a3c9 commit 6995aba
Show file tree
Hide file tree
Showing 22 changed files with 591 additions and 53 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
## [v0.2.0](https://github.com/jjzcru/hog/tree/v0.2.0) (2020-05-03)
[Release](https://github.com/jjzcru/hog/releases/tag/v0.2.0)

**Commands 🤖:**
- **[set]** Create command
- **[get]** Create command
- **[remove]** Users are able to remove multiple buckets under the same command

**Documentation 📖:**
- **[set]** Create documentation
- **[get]** Create documentation
- **[add]** Update documentation for the `url` flag
- Add `Usage` section in the `README.md`

**Flags 🚩:**
- **--url** Add flag to **[add]** command

**Misc 👾:**
- Use regex instead of exact match for the **[remove]** command
- Use regex instead of exact match for the **[update]** command
- Rename hog file from `hog.yml` to `.hog.yml`

## [v0.1.0](https://github.com/jjzcru/hog/tree/v0.1.0) (2020-05-03)
[Release](https://github.com/jjzcru/hog/releases/tag/v0.1.0)

Expand Down
48 changes: 47 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Since it's written in [Go][go], most of the commands runs across multiple operat
## Table of contents
* [Getting Started](#getting-started)
+ [Installation](#installation)
+ [Usage](#usage)
* [Syntax](#syntax)
* [Use Cases](#use-cases)
* [Commands](#commands)
Expand All @@ -30,7 +31,7 @@ Since it's written in [Go][go], most of the commands runs across multiple operat
The main use case for `hog` is that you are able to share your files with other people directly from your machine
without any intermediary _(Dropbox, Google Drive, WeTransfer)_.

`hog` uses a file called `hog.yml` to store the references from your files, by default this file is located in your
`hog` uses a file called `.hog.yml` to store the references from your files, by default this file is located in your
home directory but you can change the directory used by `hog` by setting the `env` variable `HOG_PEN`.

`hog` groups your files in `buckets` which are just a list of paths inside your file system for the files you would
Expand Down Expand Up @@ -59,6 +60,47 @@ are on `windows` you can ignore this step.
3. Add the binary to `$PATH`.
4. Run `hog version` to make sure that the binary is installed.

### Usage

#### Start Server

First you need to start the server so the application is able to serve the files.

```
hog start -d
```

By default the application will run at port `1618` and the endpoint for download is `/download/{BucketID}`. For more
information about how the `start` command works go to [start][start] documentation.

#### Add files

Now you need to add files to serve, for this go to your terminal and navigate to file or directory that you want to
share and run the `add` command.
```
hog add file.png ./file.jpg /home/root/file.pdf
```

You can add multiple files which are going to be group together as a bucket, you can add relative path, name of files
or directories or absolute paths. This command will return the `BucketID` that was created.

#### Share your bucket

To share, after you run the `add` command, you need to use the `BucketID` to generate the link. Lets say that the server
is running on port `1618` and the `BucketID` generated is `2iez0Wa`. Now you just need to create a url that targets
your computer in that port.

```
// For localhost
http://localhost:1618/download/2iez0Wa
// For IP
http://192.168.1.101:1618/download/2iez0Wa
// For domain
http://my.domain.com:1618/download/2iez0Wa
```

## Syntax
The syntax consists of:
- `domain`: The domain that is use to reference the address of the machine, this value is used by some sharing
Expand Down Expand Up @@ -105,7 +147,9 @@ link and the file will automatically download.
| ------- | ------ | ------- |
| [add][add] | Group files in a bucket | `hog add [files] [flags]` |
| [bucket][bucket] | Display the buckets and their files | `hog bucket [flags]` |
| [get][get] | Get hog configuration values | `hog get [command]` |
| [remove][remove] | Remove a bucket by its id | `hog remove {id} [flags]` |
| [set][set] | Set hog configuration values | `hog set [command]` |
| [start][start] | Start hog service | `hog start [flags]` |
| [update][update] | Update the files in a bucket by its id | `hog update {id} [files] [flags]`|
| [version][version]| Display version number | `hog version [flags]` |
Expand All @@ -126,7 +170,9 @@ To learn more about the progress and what is being planned go to [Projects][proj

[add]: docs/commands/add.md
[bucket]: docs/commands/bucket.md
[get]: docs/commands/get.md
[remove]: docs/commands/remove.md
[set]: docs/commands/set.md
[start]: docs/commands/start.md
[update]: docs/commands/update.md
[version]: docs/commands/version.md
12 changes: 12 additions & 0 deletions docs/commands/add.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ Then it will return the `id` for the bucket.
hog add test.jpg
hog add test_1.jpg ./test_2.jpb
hog add test.jpg /home/example/download/file.pdf
hog add test.jpg /home/example/download/file.pdf --url
hog add test.jpg /home/example/download/file.pdf -u
```

## Flags
| Flag | Short code | Description |
| ------- | ------ | ------- |
| [ttl](#ttl) | | Remove a bucket after a period of time |
| [url](#url) | u | Return a share url as response |

### ttl

Expand All @@ -34,4 +37,13 @@ hog add test.jpg --ttl 10s
hog add test.jpg test_1.png --ttl 1m
```

### url

This flag if enable will return an url to share, created by using the configuration inside `.hog.yml`.

```
hog add test.jpg --url
hog add test.jpg test_1.png -u
```

[time-to-live]: https://www.cloudflare.com/learning/cdn/glossary/time-to-live-ttl/
52 changes: 52 additions & 0 deletions docs/commands/get.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
get
==========

Get hog configuration values.

_This values comes from the file `.hog.yml`_

## Syntax
```
hog get [command]
```

## Example
```
hog get protocol
hog get domain
hog get port
```

## Command

### protocol

Get protocol value. Should be `http` or `https`.

#### Syntax
```
hog get protocol
```

### domain

Get domain value.

_This is the domain from which the devices are going to reach the server, can be an ip like `192.168.1.101` or a
public domain like `example.com`. This value is used for sharing functionalities_

#### Syntax
```
hog get domain
```

### port

Get port value.

_This value should be a number_

#### Syntax
```
hog get port
```
2 changes: 1 addition & 1 deletion docs/commands/remove.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Remove a bucket by its id
hog remove {id} [flags]
```

This command takes only one id as argument. It will check if the bucket exists inside `hog.yml` and will remove the
This command takes only one id as argument. It will check if the bucket exists inside `.hog.yml` and will remove the
reference from the file. By default this command runs immediately, if you which to delay the deletion use one of the
flags described below.

Expand Down
58 changes: 58 additions & 0 deletions docs/commands/set.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
set
==========

Set hog configuration values.

_This command will update the values in the file `.hog.yml`_

## Syntax
```
hog set [command]
```

## Example
```
hog set protocol http
hog set protocol https
hog set domain localhost
hog set domain 192.168.1.101
hog set domain example.com
hog set port 3000
```

## Command

### protocol

Set protocol value. This value can only be `http` or `https`.

#### Syntax
```
hog set protocol http
hog set protocol https
```

### domain

Set domain value.

_This is the domain from which the devices are going to reach the server, can be an ip like `192.168.1.101` or a
public domain like `example.com`. This value is used for sharing functionalities_

#### Syntax
```
hog set domain localhost
hog set domain 192.168.1.101
hog set domain example.com
```

### port

Set port value.

_This value must be a number_

#### Syntax
```
hog set port 3000
```
2 changes: 1 addition & 1 deletion docs/commands/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Start hog service
hog start [flags]
```

This command use the `hog.yml` file to fetch the bucket ids that are going to be serve to download.
This command use the `.hog.yml` file to fetch the bucket ids that are going to be serve to download.
To download any bucket you need to call the endpoint `/download/{BucketID}` depending on the amount of files and
the path the download is going to be as following:

Expand Down
2 changes: 1 addition & 1 deletion docs/commands/update.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Update the files in a bucket by its id
hog update {id} [files] [flags]
```

This command takes only one id as argument. It will check if the bucket exists inside `hog.yml` and will overwrite
This command takes only one id as argument. It will check if the bucket exists inside `.hog.yml` and will overwrite
the files inside the bucket with the files provided.

## Examples
Expand Down
21 changes: 18 additions & 3 deletions internal/command/add/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,25 @@ import (
"github.com/spf13/cobra"
)

// Command returns a cobra command for `init` sub command
// Command returns a cobra command for `add` sub command
func Command() *cobra.Command {
cmd := &cobra.Command{
Use: "add",
Short: "Group files in a bucket",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
bucketID, err := run(cmd, args)
response, err := run(cmd, args)
if err != nil {
utils.PrintError(err)
return
}

fmt.Println(bucketID)
fmt.Println(response)
},
}

cmd.Flags().Duration("ttl", 0, "Remove a bucket after a period of time")
cmd.Flags().BoolP("url", "u", false, "Return a share url as response")

return cmd
}
Expand All @@ -39,6 +40,11 @@ func run(cmd *cobra.Command, args []string) (string, error) {
return "", err
}

isUrl, err := cmd.Flags().GetBool("url")
if err != nil {
return "", err
}

var files []string
for _, file := range args {
filePath, err := filepath.Abs(file)
Expand Down Expand Up @@ -73,5 +79,14 @@ func run(cmd *cobra.Command, args []string) (string, error) {
}
}

if isUrl {
h, err := hog.Get()
if err != nil {
return "", err
}

return fmt.Sprintf("%s://%s:%d/download/%s", h.Protocol, h.Domain, h.Port, bucketID), nil
}

return bucketID, nil
}
7 changes: 5 additions & 2 deletions internal/command/bucket/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/spf13/cobra"
)

// Command returns a cobra command for `init` sub command
// Command returns a cobra command for `bucket` sub command
func Command() *cobra.Command {
cmd := &cobra.Command{
Use: "bucket",
Expand All @@ -30,7 +30,7 @@ func Command() *cobra.Command {

func run() error {

hogPath, err := hog.GetPath()
hogPath, err := hog.Path()
if err != nil {
return err
}
Expand Down Expand Up @@ -84,6 +84,9 @@ func getHog(hogPath string) (hog.Hog, error) {
func transform(h hog.Hog) [][]string {
var table [][]string
for id, files := range h.Buckets {
if len(files) == 0 {
table = append(table, []string{id, "EMPTY"})
}
for _, file := range files {
table = append(table, []string{id, file})
}
Expand Down
4 changes: 4 additions & 0 deletions internal/command/command.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package command

import (
"github.com/jjzcru/hog/internal/command/get"
"github.com/jjzcru/hog/internal/command/set"
"os"

"github.com/jjzcru/hog/internal/command/add"
Expand Down Expand Up @@ -31,6 +33,8 @@ func Execute() error {
start.Command(),
bucket.Command(),
version.Command(),
set.Command(),
get.Command(),
)

return rootCmd.Execute()
Expand Down
Loading

0 comments on commit 6995aba

Please sign in to comment.