Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] use RFC3339 dates format #5

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 16 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@ A command-line interface for working with SMS Gateway for Android.
- [Commands](#commands)
- [Send a message](#send-a-message)
- [Get the status of a sent message](#get-the-status-of-a-sent-message)
- [Usage Examples](#usage-examples)
- [Output formats](#output-formats-1)
- [Text](#text)
- [JSON](#json)
- [Raw](#raw)
- [Exit codes](#exit-codes)
- [Exit codes](#exit-codes)
- [Examples](#examples)
- [Output formats](#output-formats-1)
- [Support](#support)
- [Contributing](#contributing)
- [License](#license)
Expand Down Expand Up @@ -121,9 +118,16 @@ Syntax:
smsgate status 'Message ID'
```

<p align="right">(<a href="#readme-top">back to top</a>)</p>
### Exit codes

## Usage Examples
The CLI uses exit codes to indicate the outcome of operations:

- `0`: success
- `1`: invalid options or arguments
- `2`: server request error
- `3`: output formatting error

### Examples

For security reasons, it is recommended to pass credentials using environment variables or a `.env` file.

Expand Down Expand Up @@ -153,9 +157,9 @@ If you prefer not to install the CLI tool locally, you can use Docker to run it:
docker run -it --rm --env-file .env ghcr.io/android-sms-gateway/cli send --phone '+19162255887' 'Hello, Dr. Turk!'
```

### Output formats
#### Output formats

#### Text
**Text**

```
ID: zXDYfTmTVf3iMd16zzdBj
Expand All @@ -167,7 +171,7 @@ Recipients:
+19162255888 Pending
```

#### JSON
**JSON**

```json
{
Expand All @@ -189,25 +193,14 @@ Recipients:
}
```

#### Raw
**Raw**

```json
{"id":"zXDYfTmTVf3iMd16zzdBj","state":"Pending","isHashed":false,"isEncrypted":false,"recipients":[{"phoneNumber":"+19162255887","state":"Pending"},{"phoneNumber":"+19162255888","state":"Pending"}],"states":{}}
```

<p align="right">(<a href="#readme-top">back to top</a>)</p>

## Exit codes

The CLI uses exit codes to indicate the outcome of operations:

- `0`: success
- `1`: invalid options or arguments
- `2`: server request error
- `3`: output formatting error

<p align="right">(<a href="#readme-top">back to top</a>)</p>

## Support

For support, please contact [email protected]
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/messages/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var send = &cli.Command{
&cli.TimestampFlag{
Name: "validUntil",
Usage: "Valid until",
Layout: time.DateTime,
Layout: time.RFC3339,
Timezone: time.Local,
},
},
Expand Down
32 changes: 16 additions & 16 deletions internal/core/output/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,6 @@ func (*TextOutput) MessageState(src smsgateway.MessageState) (string, error) {
builder.WriteString("\nIsEncrypted: ")
builder.WriteString(boolToString(src.IsEncrypted))

if len(src.States) > 0 {
builder.WriteString("\nStates: ")

for _, k := range messageStates {
v, ok := src.States[k]
if !ok {
continue
}

builder.WriteString("\n\t")
builder.WriteString(k)
builder.WriteString("\t")
builder.WriteString(v.Local().Format(time.DateTime))
}
}

builder.WriteString("\nRecipients: ")

for _, r := range src.Recipients {
Expand All @@ -64,5 +48,21 @@ func (*TextOutput) MessageState(src smsgateway.MessageState) (string, error) {
}
}

if len(src.States) > 0 {
builder.WriteString("\nStates: ")

for _, k := range messageStates {
v, ok := src.States[k]
if !ok {
continue
}

builder.WriteString("\n\t")
builder.WriteString(k)
builder.WriteString("\t")
builder.WriteString(v.Local().Format(time.RFC3339))
}
}

return builder.String(), nil
}