Skip to content

Commit

Permalink
Add config command.
Browse files Browse the repository at this point in the history
Resolve #666

Signed-off-by: Ross Goldberg <[email protected]>
  • Loading branch information
rgoldberg committed Jan 3, 2025
1 parent 55244d9 commit cfe7ced
Show file tree
Hide file tree
Showing 11 changed files with 168 additions and 109 deletions.
159 changes: 57 additions & 102 deletions .github/ISSUE_TEMPLATE/01-bug-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,134 +6,89 @@ body:
- type: markdown
attributes:
value: |
# Console command & output formatting
# Configuration
- type: textarea
id: config
attributes:
label: mas config
description: The output of `mas config --markdown`
value: |
<!--
If `mas config --markdown` runs without error, replace the contents of this text area with its output.
When providing commands & output, please use the following format (where `…` is a placeholder):
Otherwise, your mas version does not have `mas config`, so provide the following:
-->
- Use a multiline console block: start with ```` ```console ````, end with ```` ``` ````, each on its own line
- Prefix each non-console step (or comment) with two hashes & a space: `## …`
- Remove shell prompts; instead, prefix each console command with a dollar sign & a space: `$ …`
- Prefix each output line beginning with `#`, `$`, `%`, or `>` with an additional instance of that <!--
--> character: `##…`, `$$…`, `%%…`, or `>>…`
- Write all other output lines without any prefix: `…`
### Output of `mas version`
<!--Example: "1.8.8"-->
e.g.:
### Output of `sw_vers -productVersion`
<!--Example: "15.1.1"-->
````text
```console
## In the Mac App Store GUI, …
$ mas list
123 App 1 (4.5.6)
124 App 2 (10.2)
```
````
# Environment
- type: input
id: mas-version
attributes:
label: mas version
description: The output of `mas version`
placeholder: "example: 1.8.7"
validations:
required: true
- type: input
id: macos-version
attributes:
label: macOS version
description: The output of `sw_vers -productVersion`
placeholder: "example: 15.1.1"
validations:
required: true
- type: input
id: macos-build
attributes:
label: macOS build version
description: The output of `sw_vers -buildVersion`
placeholder: "example: 24B2091"
validations:
required: true
- type: input
id: processor
attributes:
label: Processor
description: The output of `sysctl -n machdep.cpu.brand_string`
placeholder: "example: Apple M1"
validations:
required: true
- type: dropdown
id: install-method
attributes:
label: mas installation method
options:
- Homebrew core (brew install mas)
- Homebrew custom tap (brew install mas-cli/tap/mas)
- GitHub Releases (https://github.com/mas-cli/mas/releases)
- Built from source
- Other
default: 0
validations:
required: true
- type: textarea
id: install-details
attributes:
label: mas installation details
# yamllint disable rule:trailing-spaces
value: |
<!--if you selected the "Other" installation method, provide details below-->
### Output of `sw_vers -buildVersion`
<!--Example: "24B2091"-->
<!--if you installed from GitHub Releases, provide URL of installer below-->
### Output of `sysctl -n machdep.cpu.brand_string`
<!--Example: "Apple M1"-->
<!--if you built from source, uncomment the following comment & provide all 4 values-->
### Installation method (delete the incorrect ones)
<!--
- git origin URL:
- git revision:
- git tag/branch:
- Xcode version:
-->
# yamllint enable rule:trailing-spaces
- Homebrew core (via `brew install mas`)
- Homebrew custom tap (via `brew install mas-cli/tap/mas`)
- GitHub Releases (from <https://github.com/mas-cli/mas/releases>)
- Built from source (provide info about build)
- Other
validations:
required: false
required: true
- type: markdown
attributes:
value: |
# Issue
- type: textarea
id: expected-behavior
id: description
attributes:
label: Expected behavior
label: Bug description
placeholder:
Prefer copied, pasted & formatted commands & output in a multiline console block (as instructed
above) instead of screenshots
validations:
required: true
- type: textarea
id: actual-behavior
attributes:
label: Actual behavior
placeholder:
Prefer copied, pasted & formatted commands & output in a multiline console block (as instructed
above) instead of screenshots
Include expected & actual output, as well as other pertinent info.
validations:
required: true
- type: textarea
id: reproduction
attributes:
label: Steps to reproduce
description: |
Copy, paste & format commands & output in the multiline console block (as instructed above) that reproduce <!--
--> the bug
Copy, paste & format commands & output in the console block (as instructed below)
value: |
```console
```
validations:
required: true
- type: textarea
id: context
- type: markdown
attributes:
label: Additional context
placeholder: "example: Does the bug occur in other mas or macOS versions?"
validations:
required: false
value: |
# Console command & output formatting instructions
Provide console commands & output as copied, pasted & formatted text, instead of as screenshots.
If long descriptive text or screenshots of dialogs or apps are necessary, provide them between console blocks.
Format commands & output as follows (where `…` is a placeholder):
- Use a multiline console block: start with ```` ```console ````, end with ```` ``` ````, each on its own line
- Prefix each non-console step (or comment) with two hashes & a space: `## …`
- Remove shell prompts; instead, prefix each console command with a dollar sign & a space: `$ …`
- Prefix each output line beginning with `#`, `$`, `%`, or `>` with an additional instance of that <!--
--> character: `##…`, `$$…`, `%%…`, or `>>…`
- Write all other output lines without any prefix: `…`
e.g.:
````text
```console
## In the Mac App Store GUI, …
$ mas list
123 App 1 (4.5.6)
124 App 2 (10.2)
```
````
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
run: script/bootstrap

- name: Build
run: script/build
run: script/build build-test

- name: Test
run: script/test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
if: matrix.language == 'swift'
shell: bash
run: |
script/build
script/build codeql
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tag-pushed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
- name: 📦 Build universal executable & package it in an installer
run: |
sudo xcode-select -s /Applications/Xcode_16.2.app/Contents/Developer
script/package
script/package package
- name: 🚰 Bump custom tap formula
env:
Expand Down
94 changes: 94 additions & 0 deletions Sources/mas/Commands/Config.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
//
// Config.swift
// mas
//
// Created by Ross Goldberg on 2025-01-03.
// Copyright © 2024 mas-cli. All rights reserved.
//

import ArgumentParser
import CommerceKit

private let unknown = "unknown"

extension MAS {
/// Displays mas config & related system info.
struct Config: ParsableCommand {
static let configuration = CommandConfiguration(
abstract: "Display mas config & related system info"
)

@Flag(help: "Output as Markdown")
var markdown = false

/// Runs the command.
func run() throws {
if markdown {
print("```text")
}
print(
"""
mas ▁▁▁▁ \(Package.version)
from ▁▁▁ \(Package.installMethod)
origin ▁ \(Package.gitOrigin)
rev ▁▁▁▁ \(Package.gitRevision)
swift ▁▁ \(Package.swiftVersion)
driver ▁ \(Package.swiftDriverVersion)
region ▁ \(Storefront.isoRegion?.alpha2 ?? unknown)
macos ▁▁ \(
ProcessInfo.processInfo.operatingSystemVersionString.dropFirst(8)
.replacingOccurrences(of: "Build ", with: "")
)
mac ▁▁▁▁ \(macModel())
cpu ▁▁▁▁ \(cpuBrandString())
arch ▁▁▁ \(architecture())
"""
)
if markdown {
print("```")
}
}
}
}

private func macModel() -> String {
var name = [CTL_HW, HW_MODEL]

var size = 0
guard sysctl(&name, u_int(name.count), nil, &size, nil, 0) == 0 else {
perror("sysctl")
return unknown
}

var buffer = [CChar](repeating: 0, count: size)
guard sysctl(&name, u_int(name.count), &buffer, &size, nil, 0) == 0 else {
perror("sysctl")
return unknown
}

return String(cString: buffer)
}

private func cpuBrandString() -> String {
configValue("machdep.cpu.brand_string")
}

private func architecture() -> String {
configValue("hw.machine")
}

private func configValue(_ name: String) -> String {
var size = 0
guard sysctlbyname(name, nil, &size, nil, 0) == 0 else {
perror("sysctlbyname")
return unknown
}

var buffer = [CChar](repeating: 0, count: size)
guard sysctlbyname(name, &buffer, &size, nil, 0) == 0 else {
perror("sysctlbyname")
return unknown
}

return String(cString: buffer)
}
1 change: 1 addition & 0 deletions Sources/mas/MAS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct MAS: ParsableCommand {
abstract: "Mac App Store command-line interface",
subcommands: [
Account.self,
Config.self,
Home.self,
Info.self,
Install.self,
Expand Down
4 changes: 4 additions & 0 deletions contrib/completion/mas.fish
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ complete -c mas -f
### account
complete -c mas -n "__fish_use_subcommand" -f -a account -d "Display the Apple ID signed in in the Mac App Store"
complete -c mas -n "__fish_seen_subcommand_from help" -xa "account"
### config
complete -c mas -n "__fish_use_subcommand" -f -a config -d "Display mas config & related system info"
complete -c mas -n "__fish_seen_subcommand_from help" -xa "config"
complete -c mas -n "__fish_seen_subcommand_from config" -l markdown -d "Output as Markdown"
### help
complete -c mas -n "__fish_use_subcommand" -f -a help -d "Display general or command-specific help"
complete -c mas -n "__fish_seen_subcommand_from help" -xa "help"
Expand Down
4 changes: 2 additions & 2 deletions script/build
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@

printf $'==> 🏗️ Building mas %s\n' "$(script/version)"

script/generate_package_swift
script/generate_package_swift "${1:-}"

swift build --configuration release "${@}"
swift build --configuration release "${@:2}"
5 changes: 5 additions & 0 deletions script/generate_package_swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,10 @@ cat <<EOF >Sources/mas/Package.swift
/// Generated by \`script/generate_package_swift\`.
enum Package {
static let version = "$(script/version)"
static let installMethod = "${1:-unknown}"
static let gitOrigin = "$(git remote get-url origin)"
static let gitRevision = "$(git rev-parse HEAD)"
static let swiftVersion = "$(printf %s "${${$(swift --version 2>/dev/null)#Apple Swift version }%%$'\n'*}")"
static let swiftDriverVersion = "$(printf %s "${${$((swift --version 3>&2 2>&1 1>&3) 2>/dev/null)#swift-driver version: }% }")"
}
EOF
2 changes: 1 addition & 1 deletion script/lint
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ for source in Package.swift Sources Tests; do
done

printf -- $'--> 🐚 ShellCheck\n'
shellcheck -s bash -o all -e SC1088,SC2296,SC2301,SC2312 -a -P SCRIPTDIR script/**/*(.)
shellcheck -s bash -o all -e SC1088,SC1102,SC2296,SC2299,SC2300,SC2301,SC2312 -a -P SCRIPTDIR script/**/*(.)
((exit_code |= ${?}))

printf -- $'--> 〽️ Markdown\n'
Expand Down
2 changes: 1 addition & 1 deletion script/package
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

. "${0:a:h}/_setup_script"

script/build --arch arm64 --arch x86_64
script/build "${1:-}" --arch arm64 --arch x86_64

build_dir=.build
destination_root="${build_dir}/destination"
Expand Down

0 comments on commit cfe7ced

Please sign in to comment.