Skip to content

Commit 16c7b25

Browse files
Merge branch 'release-0-10-0'
2 parents ed662ac + 5f9df03 commit 16c7b25

17 files changed

Lines changed: 601 additions & 361 deletions

File tree

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Run GoReleaser
2121
uses: goreleaser/goreleaser-action@v1
2222
with:
23-
version: latest
23+
version: v1.6.3
2424
args: release --rm-dist
2525
key: ${{ secrets.YOUR_PRIVATE_KEY }}
2626
env:

.goreleaser.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ changelog:
3636
exclude:
3737
- '^docs:'
3838
- '^test:'
39+
- '^chore:'
40+
release:
41+
footer: |
42+
## Downloads
43+
| Platform | Download link |
44+
|----------|-------------------------------------------------------------------------------------------------------------------------------|
45+
| Linux | [deb package](https://github.com/claudiodangelis/qrcp/releases/download/{{ .Tag }}/qrcp_{{ .Tag }}_linux_x86_64.deb) |
46+
| Linux | [RPM package](https://github.com/claudiodangelis/qrcp/releases/download/{{ .Tag }}/qrcp_{{ .Tag }}_linux_x86_64.rpm) |
47+
| macOS | [macOS package](https://github.com/claudiodangelis/qrcp/releases/download/{{ .Tag }}/qrcp_{{ .Tag }}_macOS_x86_64.tar.gz) |
48+
| Windows | [Windows package](https://github.com/claudiodangelis/qrcp/releases/download/{{ .Tag }}/qrcp_{{ .Tag }}_Windows_x86_64.tar.gz) |
49+
50+
Refer to the list of assets below for all supported platform.
3951
nfpms:
4052
- replacements:
4153
darwin: macOS

README.md

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ Transfer files over Wi-Fi from your computer to a mobile device by scanning a QR
88

99
You can support development by donating with [![Buy Me A Coffee](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/claudiodangelis).
1010

11-
Join the **Telegram channel** [qrcp_dev](https://t.me/qrcp_dev) for news about the development.
11+
Join the **Telegram channel** [qrcp_dev](https://t.me/qrcp_dev) or the [@qrcp_dev](https://twitter.com/qrcp_dev) **Twitter account** for news about the development.
12+
1213

1314
## How does it work?
1415
![Screenshot](docs/screenshot.png)
@@ -44,6 +45,10 @@ _Note: it requires go 1.8_
4445

4546
go get github.com/claudiodangelis/qrcp
4647

48+
If using go 1.18 or higher,
49+
50+
go install github.com/claudiodangelis/qrcp@latest
51+
4752
## Linux
4853

4954
Download the latest Linux .tar.gz archive from the [Releases](https://github.com/claudiodangelis/qrcp/releases) page, extract it, move the binary to the proper directory, then set execution permissions.
@@ -186,9 +191,40 @@ qrcp receive --output=/tmp/dir
186191
```
187192

188193

189-
## Options
194+
## Configuration
195+
196+
`qrcp` works without any prior configuration, however, you can choose to configure to use specific values.
197+
198+
To configure `qrcp` you can create a configuration file inside `$XDG_CONFIG_HOME/qrcp`.
199+
200+
> Note: On Linux, the `$XDG_CONFIG_HOME` is `.config` under user home directory.
201+
> So, for example, on Linux the configuration file will be `$HOME/.config/qrcp/config.yml`.
202+
203+
> Note: Starting from version 0.10.0, qrcp uses a YAML configuration file instead of the old JSON one. You can automatically migrate the legacy JSON format to the new YAML format by running `qrcp config migrate`.
204+
205+
| Key | Type | Notes |
206+
|-------------|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
207+
| `interface` | String | This value is automatically discovered during the first launch of `qrcp`, you can set it to override the default. You can use the `any` interface to bind the web server to `0.0.0.0`. |
208+
| `bind` | String | This value is used by qrcp to bind the web server to. Note: if this value is set, the `interface` parameter is ignored. |
209+
| `port` | Integer | When this value is not set, `qrcp` will pick a random port at any launch. |
210+
| `path` | String | When this value is not set, `qrcp` will add a random string at the end of URL. |
211+
| `output` | String | Default directory to receive files to. If empty, the current working directory is used. |
212+
| `fqdn` | String | When this value is set, `qrcp` will use it to replace the IP address in the generated URL. |
213+
| `keepAlive` | Bool | Controls whether `qrcp` should quit after transferring the file. Defaults to `false`. |
214+
| `secure` | Bool | Controls whether `qrcp` should use HTTPS instead of HTTP. Defaults to `false` |
215+
| `tls-cert` | String | Path to the TLS certificate. It's only used when `secure: true`. |
216+
| `tls-key` | String | Path to the TLS key. It's only used when `secure: true`. |
190217

191-
`qrcp` works without any prior configuration, however, you can choose to configure to use specific values. The `config` command launches a wizard that lets you configure parameters like interface, port, fully-qualified domain name and keep alive.
218+
219+
All the configuration parameters can be controlled via environment variables prefixed with `QRCP_`, for example:
220+
- `$QRCP_INTERFACE`
221+
- `$QRCP_PORT`
222+
- `$QRCP_KEEPALIVE`
223+
- _etc_
224+
225+
### Config Wizard
226+
227+
The `config` command launches a wizard that lets you configure parameters like interface, port, fully-qualified domain name and keep alive.
192228

193229
```sh
194230
qrcp config
@@ -203,10 +239,10 @@ qrcp --list-all-interfaces config
203239

204240
### Configuration File
205241

206-
The default configuration file is stored in $XDG_CONFIG_HOME/qrcp/config.json, however, you can specify the location of the config file by passing the `--config` flag:
242+
The default configuration file is stored in $XDG_CONFIG_HOME/qrcp/config.yml, however, you can specify the location of the config file by passing the `--config` flag:
207243

208244
```sh
209-
qrcp --config /tmp/qrcp.json MyDocument.pdf
245+
qrcp --config /tmp/qrcp.yml MyDocument.pdf
210246
```
211247

212248
### Port
@@ -247,6 +283,13 @@ This is useful when you want to transfer files from your Amazon EC2, Digital Oce
247283
qrcp -i any MyDocument.pdf
248284
```
249285

286+
### Bind
287+
288+
Alternatively to choosing the interface, you can directly specify the address you want `qrcp` to bind the webserver to.
289+
290+
```sh
291+
qrcp --bind 10.20.30.40 MyDocument.pdf
292+
```
250293

251294
### URL
252295

@@ -349,7 +392,7 @@ To load completions for each session, execute once:
349392

350393
## Authors
351394

352-
**qrcp**, originally called **qr-filetransfer**, started from an idea of [Claudio d'Angelis](claudiodangelis@gmail.com) ([@daw985](https://twitter.com/daw985) on Twitter), the current maintainer, and it's [developed by the community](https://github.com/claudiodangelis/qrcp/graphs/contributors).
395+
**qrcp**, originally called **qr-filetransfer**, started from an idea of [Claudio d'Angelis](claudiodangelis@gmail.com) ([@claudiodangelis](https://t.me/claudiodangelis) on Telegram), the current maintainer, and it's [developed by the community](https://github.com/claudiodangelis/qrcp/graphs/contributors).
353396

354397

355398
[Join us!](https://github.com/claudiodangelis/qrcp/fork)

application/application.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package application
2+
3+
type Flags struct {
4+
Quiet bool
5+
KeepAlive bool
6+
ListAllInterfaces bool
7+
Port int
8+
Path string
9+
Interface string
10+
Bind string
11+
FQDN string
12+
Zip bool
13+
Config string
14+
Browser bool
15+
Secure bool
16+
TlsCert string
17+
TlsKey string
18+
Output string
19+
}
20+
21+
type App struct {
22+
Flags Flags
23+
Name string
24+
}
25+
26+
func New() App {
27+
return App{
28+
Name: "qrcp",
29+
Flags: Flags{},
30+
}
31+
}

cmd/config.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package cmd
22

33
import (
4+
"fmt"
5+
46
"github.com/claudiodangelis/qrcp/config"
57
"github.com/spf13/cobra"
68
)
79

810
func configCmdFunc(command *cobra.Command, args []string) error {
9-
return config.Wizard(configFlag, listallinterfacesFlag)
11+
return config.Wizard(app)
1012
}
1113

1214
var configCmd = &cobra.Command{
@@ -16,3 +18,18 @@ var configCmd = &cobra.Command{
1618
Aliases: []string{"c", "cfg"},
1719
RunE: configCmdFunc,
1820
}
21+
22+
var migrateCmd = &cobra.Command{
23+
Use: "migrate",
24+
Short: "Migrate the legacy configuration file",
25+
Long: "Migrate the legacy JSON configuration file to the new YAML format",
26+
Run: func(cmd *cobra.Command, args []string) {
27+
ok, err := config.Migrate(app)
28+
if err != nil {
29+
fmt.Println("error while migrating the legacy JSON configuration file:", err)
30+
}
31+
if ok {
32+
fmt.Println("Legacy JSON configuration file has been successfully deleted")
33+
}
34+
},
35+
}

cmd/qrcp.go

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,39 @@
11
package cmd
22

33
import (
4+
"github.com/claudiodangelis/qrcp/application"
45
"github.com/spf13/cobra"
56
)
67

8+
var app application.App
9+
710
func init() {
11+
app = application.New()
812
rootCmd.AddCommand(sendCmd)
913
rootCmd.AddCommand(receiveCmd)
1014
rootCmd.AddCommand(configCmd)
1115
rootCmd.AddCommand(versionCmd)
1216
rootCmd.AddCommand(completionCmd)
17+
configCmd.AddCommand(migrateCmd)
1318
// Global command flags
14-
rootCmd.PersistentFlags().BoolVarP(&quietFlag, "quiet", "q", false, "only print errors")
15-
rootCmd.PersistentFlags().BoolVarP(&keepaliveFlag, "keep-alive", "k", false, "keep server alive after transferring")
16-
rootCmd.PersistentFlags().BoolVarP(&listallinterfacesFlag, "list-all-interfaces", "l", false, "list all available interfaces when choosing the one to use")
17-
rootCmd.PersistentFlags().IntVarP(&portFlag, "port", "p", 0, "port to use for the server")
18-
rootCmd.PersistentFlags().StringVar(&pathFlag, "path", "", "path to use. Defaults to a random string")
19-
rootCmd.PersistentFlags().StringVarP(&interfaceFlag, "interface", "i", "", "network interface to use for the server")
20-
rootCmd.PersistentFlags().StringVarP(&fqdnFlag, "fqdn", "d", "", "fully-qualified domain name to use for the resulting URLs")
21-
rootCmd.PersistentFlags().BoolVarP(&zipFlag, "zip", "z", false, "zip content before transferring")
22-
rootCmd.PersistentFlags().StringVarP(&configFlag, "config", "c", "", "path to the config file, defaults to $XDG_CONFIG_HOME/qrcp/config.json")
23-
rootCmd.PersistentFlags().BoolVarP(&browserFlag, "browser", "b", false, "display the QR code in a browser window")
24-
rootCmd.PersistentFlags().BoolVarP(&secureFlag, "secure", "s", false, "use https connection")
25-
rootCmd.PersistentFlags().StringVar(&tlscertFlag, "tls-cert", "", "path to TLS certificate to use with HTTPS")
26-
rootCmd.PersistentFlags().StringVar(&tlskeyFlag, "tls-key", "", "path to TLS private key to use with HTTPS")
19+
rootCmd.PersistentFlags().BoolVarP(&app.Flags.Quiet, "quiet", "q", false, "only print errors")
20+
rootCmd.PersistentFlags().BoolVarP(&app.Flags.KeepAlive, "keep-alive", "k", false, "keep server alive after transferring")
21+
rootCmd.PersistentFlags().BoolVarP(&app.Flags.ListAllInterfaces, "list-all-interfaces", "l", false, "list all available interfaces when choosing the one to use")
22+
rootCmd.PersistentFlags().IntVarP(&app.Flags.Port, "port", "p", 0, "port to use for the server")
23+
rootCmd.PersistentFlags().StringVar(&app.Flags.Path, "path", "", "path to use. Defaults to a random string")
24+
rootCmd.PersistentFlags().StringVarP(&app.Flags.Interface, "interface", "i", "", "network interface to use for the server")
25+
rootCmd.PersistentFlags().StringVar(&app.Flags.Bind, "bind", "", "address to bind the web server to")
26+
rootCmd.PersistentFlags().StringVarP(&app.Flags.FQDN, "fqdn", "d", "", "fully-qualified domain name to use for the resulting URLs")
27+
rootCmd.PersistentFlags().BoolVarP(&app.Flags.Zip, "zip", "z", false, "zip content before transferring")
28+
rootCmd.PersistentFlags().StringVarP(&app.Flags.Config, "config", "c", "", "path to the config file, defaults to $XDG_CONFIG_HOME/qrcp/config.json")
29+
rootCmd.PersistentFlags().BoolVarP(&app.Flags.Browser, "browser", "b", false, "display the QR code in a browser window")
30+
rootCmd.PersistentFlags().BoolVarP(&app.Flags.Secure, "secure", "s", false, "use https connection")
31+
rootCmd.PersistentFlags().StringVar(&app.Flags.TlsCert, "tls-cert", "", "path to TLS certificate to use with HTTPS")
32+
rootCmd.PersistentFlags().StringVar(&app.Flags.TlsKey, "tls-key", "", "path to TLS private key to use with HTTPS")
2733
// Receive command flags
28-
receiveCmd.PersistentFlags().StringVarP(&outputFlag, "output", "o", "", "output directory for receiving files")
34+
receiveCmd.PersistentFlags().StringVarP(&app.Flags.Output, "output", "o", "", "output directory for receiving files")
2935
}
3036

31-
// Flags
32-
var zipFlag bool
33-
var portFlag int
34-
var interfaceFlag string
35-
var outputFlag string
36-
var keepaliveFlag bool
37-
var quietFlag bool
38-
var fqdnFlag string
39-
var pathFlag string
40-
var listallinterfacesFlag bool
41-
var configFlag string
42-
var browserFlag bool
43-
var secureFlag bool
44-
var tlscertFlag string
45-
var tlskeyFlag string
46-
4737
// The root command (`qrcp`) is like a shortcut of the `send` command
4838
var rootCmd = &cobra.Command{
4939
Use: "qrcp",

cmd/receive.go

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,9 @@ import (
1212
)
1313

1414
func receiveCmdFunc(command *cobra.Command, args []string) error {
15-
log := logger.New(quietFlag)
15+
log := logger.New(app.Flags.Quiet)
1616
// Load configuration
17-
configOptions := config.Options{
18-
Interface: interfaceFlag,
19-
Port: portFlag,
20-
Path: pathFlag,
21-
FQDN: fqdnFlag,
22-
KeepAlive: keepaliveFlag,
23-
ListAllInterfaces: listallinterfacesFlag,
24-
Secure: secureFlag,
25-
TLSCert: tlscertFlag,
26-
TLSKey: tlskeyFlag,
27-
Output: outputFlag,
28-
}
29-
cfg, err := config.New(configFlag, configOptions)
30-
if err != nil {
31-
return err
32-
}
17+
cfg := config.New(app)
3318
// Create the server
3419
srv, err := server.New(&cfg)
3520
if err != nil {
@@ -44,7 +29,7 @@ func receiveCmdFunc(command *cobra.Command, args []string) error {
4429
log.Print(srv.ReceiveURL)
4530
// Renders the QR
4631
qr.RenderString(srv.ReceiveURL)
47-
if browserFlag {
32+
if app.Flags.Browser {
4833
srv.DisplayQR(srv.ReceiveURL)
4934
}
5035
if err := keyboard.Open(); err == nil {

cmd/send.go

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,12 @@ import (
1414
)
1515

1616
func sendCmdFunc(command *cobra.Command, args []string) error {
17-
log := logger.New(quietFlag)
18-
payload, err := payload.FromArgs(args, zipFlag)
17+
log := logger.New(app.Flags.Quiet)
18+
payload, err := payload.FromArgs(args, app.Flags.Zip)
1919
if err != nil {
2020
return err
2121
}
22-
// Load configuration
23-
configOptions := config.Options{
24-
Interface: interfaceFlag,
25-
Port: portFlag,
26-
Path: pathFlag,
27-
FQDN: fqdnFlag,
28-
KeepAlive: keepaliveFlag,
29-
ListAllInterfaces: listallinterfacesFlag,
30-
Secure: secureFlag,
31-
TLSCert: tlscertFlag,
32-
TLSKey: tlskeyFlag,
33-
}
34-
cfg, err := config.New(configFlag, configOptions)
22+
cfg := config.New(app)
3523
if err != nil {
3624
return err
3725
}
@@ -44,7 +32,7 @@ func sendCmdFunc(command *cobra.Command, args []string) error {
4432
log.Print(`Scan the following URL with a QR reader to start the file transfer, press CTRL+C or "q" to exit:`)
4533
log.Print(srv.SendURL)
4634
qr.RenderString(srv.SendURL)
47-
if browserFlag {
35+
if app.Flags.Browser {
4836
srv.DisplayQR(srv.SendURL)
4937
}
5038
if err := keyboard.Open(); err == nil {

0 commit comments

Comments
 (0)