Skip to content

Commit

Permalink
Merge branch 'release/0.11.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiodangelis committed Dec 6, 2023
2 parents 31df57b + dc7a48d commit b2fd9f2
Show file tree
Hide file tree
Showing 19 changed files with 2,072 additions and 110 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: gomod
directory: /
schedule:
interval: daily
22 changes: 18 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
name: CI
on:
push:
tags:
- '*'
jobs:
build:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.21.x'
- name: Install dependencies
run: go get .
- name: Build
run: go build -v ./...
- name: Test with the Go CLI
run: go test ./...
release:
runs-on: ubuntu-latest
needs: test
if: startsWith(github.event.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v2
# Required to build changeleg
Expand All @@ -24,4 +38,4 @@ jobs:
args: release --rm-dist
key: ${{ secrets.YOUR_PRIVATE_KEY }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Version number is defined in `cmd/version.go`.

## Releases

We are using [goreleases](https://goreleaser.com/), [nfpm](https://goreleaser.com/nfpm/) and [Github Actions](https://github.com/features/actions) to build, package and release `qrcp`.
We are using [goreleases](https://goreleaser.com/), [nfpm](https://nfpm.goreleaser.com/) and [Github Actions](https://github.com/features/actions) to build, package and release `qrcp`.

The relevant files are:

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ To configure `qrcp` you can create a configuration file inside `$XDG_CONFIG_HOME

> Note: On Linux, the `$XDG_CONFIG_HOME` is `.config` under user home directory.
> So, for example, on Linux the configuration file will be `$HOME/.config/qrcp/config.yml`.
> On MacOS, it defaults to `$HOME/Library/Application Support/qrcp/config.yml``
> 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`.
Expand All @@ -214,6 +215,7 @@ To configure `qrcp` you can create a configuration file inside `$XDG_CONFIG_HOME
| `secure` | Bool | Controls whether `qrcp` should use HTTPS instead of HTTP. Defaults to `false` |
| `tls-cert` | String | Path to the TLS certificate. It's only used when `secure: true`. |
| `tls-key` | String | Path to the TLS key. It's only used when `secure: true`. |
| `reversed` | Bool | Reverse QR code (black text on white background)?" true`. |


All the configuration parameters can be controlled via environment variables prefixed with `QRCP_`, for example:
Expand Down Expand Up @@ -420,6 +422,7 @@ Releases are handled with [goreleaser](https://goreleaser.com).
- [ezshare](https://github.com/mifi/ezshare) - Another Node.js two way file sharing tool supporting folders and multiple files
- [local_file_share](https://github.com/woshimanong1990/local_file_share) - _"share local file to other people, OR smartphone download files which is in pc"_
- [qrcp](https://github.com/pearl2201/qrcp) - a desktop app clone of `qrcp`, writing with C# and .NET Core, work for Windows.
- [swift_file](https://github.com/mateoradman/swift_file) - Rust project inspired by `qrcp`.
## License

MIT. See [LICENSE](LICENSE).
1 change: 1 addition & 0 deletions application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Flags struct {
TlsCert string
TlsKey string
Output string
Reversed bool
}

type App struct {
Expand Down
1 change: 1 addition & 0 deletions cmd/qrcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func init() {
rootCmd.PersistentFlags().BoolVarP(&app.Flags.Secure, "secure", "s", false, "use https connection")
rootCmd.PersistentFlags().StringVar(&app.Flags.TlsCert, "tls-cert", "", "path to TLS certificate to use with HTTPS")
rootCmd.PersistentFlags().StringVar(&app.Flags.TlsKey, "tls-key", "", "path to TLS private key to use with HTTPS")
rootCmd.PersistentFlags().BoolVarP(&app.Flags.Reversed, "reversed", "r", false, "Reverse QR code (black text on white background)")
// Receive command flags
receiveCmd.PersistentFlags().StringVarP(&app.Flags.Output, "output", "o", "", "output directory for receiving files")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func receiveCmdFunc(command *cobra.Command, args []string) error {
log.Print(`Scan the following URL with a QR reader to start the file transfer, press CTRL+C or "q" to exit:`)
log.Print(srv.ReceiveURL)
// Renders the QR
qr.RenderString(srv.ReceiveURL)
qr.RenderString(srv.ReceiveURL, cfg.Reversed)
if app.Flags.Browser {
srv.DisplayQR(srv.ReceiveURL)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func sendCmdFunc(command *cobra.Command, args []string) error {
srv.Send(payload)
log.Print(`Scan the following URL with a QR reader to start the file transfer, press CTRL+C or "q" to exit:`)
log.Print(srv.SendURL)
qr.RenderString(srv.SendURL)
qr.RenderString(srv.SendURL, cfg.Reversed)
if app.Flags.Browser {
srv.DisplayQR(srv.SendURL)
}
Expand Down
15 changes: 15 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Config struct {
TlsCert string `yaml:",omitempty"`
FQDN string `yaml:",omitempty"`
Output string `yaml:",omitempty"`
Reversed bool `yaml:",omitempty"`
}

var interactive bool = false
Expand Down Expand Up @@ -61,6 +62,7 @@ func New(app application.App) Config {
cfg.TlsCert = v.GetString("tls-cert")
cfg.FQDN = v.GetString("fqdn")
cfg.Output = v.GetString("output")
cfg.Reversed = v.GetBool("reversed")

// Override
if app.Flags.Interface != "" {
Expand Down Expand Up @@ -93,6 +95,9 @@ func New(app application.App) Config {
if app.Flags.Output != "" {
cfg.Output = app.Flags.Output
}
if app.Flags.Reversed {
cfg.Reversed = true
}

// Discover interface if it's not been set yet
if !interactive {
Expand Down Expand Up @@ -306,6 +311,16 @@ func Wizard(app application.App) error {
v.Set("output", output)
}
}
promptReversed := promptui.Select{
Items: []string{"No", "Yes"},
Label: "Reverse QR code (black text on white background)?",
}
if _, promptReversedResultString, err := promptReversed.Run(); err == nil {
if promptReversedResultString == "Yes" {
v.Set("reversed", true)
}
cfg.Reversed = v.GetBool("reversed")
}

return v.WriteConfig()
}
21 changes: 14 additions & 7 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import (
func TestNew(t *testing.T) {
os.Clearenv()
_, f, _, _ := runtime.Caller(0)
foundIface, err := chooseInterface(application.Flags{})
if err != nil {
panic(err)
}
testdir := filepath.Join(filepath.Dir(f), "testdata")
tempfile, err := ioutil.TempFile("", "qrcp*tmp.yml")
if err != nil {
Expand All @@ -31,7 +35,6 @@ func TestNew(t *testing.T) {
type args struct {
app application.App
}

tests := []struct {
name string
args args
Expand All @@ -46,7 +49,7 @@ func TestNew(t *testing.T) {
},
},
Config{
Interface: "wlo1",
Interface: foundIface,
Port: 9090,
},
},
Expand All @@ -59,7 +62,7 @@ func TestNew(t *testing.T) {
},
},
Config{
Interface: "wlo1",
Interface: foundIface,
},
},
{
Expand All @@ -71,7 +74,7 @@ func TestNew(t *testing.T) {
},
},
Config{
Interface: "wlo1",
Interface: foundIface,
},
},
{
Expand All @@ -83,7 +86,7 @@ func TestNew(t *testing.T) {
},
},
Config{
Interface: "wlo1",
Interface: foundIface,
Port: 18080,
KeepAlive: false,
Bind: "10.20.30.40",
Expand All @@ -93,6 +96,7 @@ func TestNew(t *testing.T) {
TlsCert: "/path/to/cert",
FQDN: "mylan.com",
Output: "/path/to/default/output/dir",
Reversed: true,
},
},
{
Expand All @@ -105,7 +109,7 @@ func TestNew(t *testing.T) {
},
},
Config{
Interface: "wlo1",
Interface: foundIface,
Port: 99999,
Bind: "10.20.30.40",
KeepAlive: false,
Expand All @@ -115,12 +119,15 @@ func TestNew(t *testing.T) {
TlsCert: "/path/to/cert",
FQDN: "mylan.com",
Output: "/path/to/default/output/dir",
Reversed: true,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := New(tt.args.app); !reflect.DeepEqual(got, tt.want) {
got := New(tt.args.app)
got.Interface = foundIface
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("New() = %v, want %v", got, tt.want)
}
})
Expand Down
3 changes: 2 additions & 1 deletion config/testdata/full.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
interface: wlo1
interface: __PLACEHOLDER_INTERFACE__
port: 18080
bind: '10.20.30.40'
keepAlive: false
Expand All @@ -8,3 +8,4 @@ tls-key: /path/to/key
tls-cert: /path/to/cert
fqdn: mylan.com
output: /path/to/default/output/dir
reversed: true
2 changes: 1 addition & 1 deletion config/testdata/qrcp.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
interface: wlo1
interface: __PLACEHOLDER_INTERFACE__
7 changes: 7 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,13 @@ qrcp --tls-cert /path/to/cert.pem --tls-key /path/to/cert.key MyDocument

A `--secure` flag is available too, you can use it to override the default value.

### Color scheme

By default, `qrcp`` is configured for terminals with light text on a dark background. Terminals with a light color scheme can invert this with the `--reversed` or `-r` flag.

```sh
qrcp --reversed MyDocument.pdf
```

### Open in browser

Expand Down
12 changes: 5 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@ module github.com/claudiodangelis/qrcp
go 1.14

require (
github.com/adrg/xdg v0.3.2
github.com/adrg/xdg v0.4.0
github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496
github.com/eiannone/keyboard v0.0.0-20200508000154-caf4b762e807
github.com/fatih/color v1.9.0 // indirect
github.com/glendc/go-external-ip v0.0.0-20170425150139-139229dcdddd
github.com/glendc/go-external-ip v0.1.0
github.com/jhoonb/archivex v0.0.0-20180718040744-0488e4ce1681
github.com/manifoldco/promptui v0.7.0
github.com/mattn/go-colorable v0.1.6 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/skip2/go-qrcode v0.0.0-20191027152451-9434209cb086
github.com/spf13/cobra v1.0.0
github.com/spf13/viper v1.4.0
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.17.0
gopkg.in/cheggaaa/pb.v1 v1.0.28
gopkg.in/yaml.v2 v2.2.2
gopkg.in/yaml.v2 v2.4.0
)
Loading

0 comments on commit b2fd9f2

Please sign in to comment.