[bug#60582,1/2] services: configuration: Format a list of packages by their names.

Message ID 11414ae2650cde429b82aa168041e3989cf7d84c.1672951913.git.mirai@makinata.eu
State New
Headers
Series [bug#60582,1/2] services: configuration: Format a list of packages by their names. |

Commit Message

Bruno Victal Jan. 5, 2023, 9:06 p.m. UTC
* gnu/services/configuration.scm
(generate-documentation): Format a list of packages by their names.
---
 gnu/services/configuration.scm | 3 +++
 1 file changed, 3 insertions(+)
  

Comments

Maxim Cournoyer Jan. 13, 2023, 8:29 p.m. UTC | #1
Hi,

Bruno Victal <mirai@makinata.eu> writes:

> * gnu/services/configuration.scm
> (generate-documentation): Format a list of packages by their names.
> ---
>  gnu/services/configuration.scm | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/gnu/services/configuration.scm b/gnu/services/configuration.scm
> index 6b0291dc00..16e2380709 100644
> --- a/gnu/services/configuration.scm
> +++ b/gnu/services/configuration.scm
> @@ -370,6 +370,9 @@ (define (show-default val)
>                       (cond
>                        ((package? val)
>                         (symbol->string (package->symbol val)))
> +                      ((and ((list-of package?) val) (not (null? val)))
> +                       (format #f "(~{~a~^ ~})"
> +                        (map package->symbol val)))

The 'and' and (not (null? val)) don't seem to be necessary as in the
empty list of packages, it'd produce the same as the else clause below:

--8<---------------cut here---------------start------------->8---
scheme@(gnu services configuration)> (format #f "(~{~a~^ ~})" '())
$1 = "()"
scheme@(gnu services configuration)> (str '())
$2 = "()"
--8<---------------cut here---------------end--------------->8---

>                        (else (str val))))
>  
>                     `(entry (% (heading
  
Bruno Victal Jan. 13, 2023, 8:34 p.m. UTC | #2
On 2023-01-13 20:29, Maxim Cournoyer wrote:
> Hi,
> 
> Bruno Victal <mirai@makinata.eu> writes:
> 
>> * gnu/services/configuration.scm
>> (generate-documentation): Format a list of packages by their names.
>> ---
>>  gnu/services/configuration.scm | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/gnu/services/configuration.scm b/gnu/services/configuration.scm
>> index 6b0291dc00..16e2380709 100644
>> --- a/gnu/services/configuration.scm
>> +++ b/gnu/services/configuration.scm
>> @@ -370,6 +370,9 @@ (define (show-default val)
>>                       (cond
>>                        ((package? val)
>>                         (symbol->string (package->symbol val)))
>> +                      ((and ((list-of package?) val) (not (null? val)))
>> +                       (format #f "(~{~a~^ ~})"
>> +                        (map package->symbol val)))
> 
> The 'and' and (not (null? val)) don't seem to be necessary as in the
> empty list of packages, it'd produce the same as the else clause below:
> 
> --8<---------------cut here---------------start------------->8---
> scheme@(gnu services configuration)> (format #f "(~{~a~^ ~})" '())
> $1 = "()"
> scheme@(gnu services configuration)> (str '())
> $2 = "()"
> --8<---------------cut here---------------end--------------->8---
> 
>>                        (else (str val))))
>>  
>>                     `(entry (% (heading
> 

It is necessary for non file-like fields whose default value is '().
Otherwise configuration->documentation will show blank spaces when it should show an empty list.


Cheers,
Bruno
  

Patch

diff --git a/gnu/services/configuration.scm b/gnu/services/configuration.scm
index 6b0291dc00..16e2380709 100644
--- a/gnu/services/configuration.scm
+++ b/gnu/services/configuration.scm
@@ -370,6 +370,9 @@  (define (show-default val)
                      (cond
                       ((package? val)
                        (symbol->string (package->symbol val)))
+                      ((and ((list-of package?) val) (not (null? val)))
+                       (format #f "(~{~a~^ ~})"
+                        (map package->symbol val)))
                       (else (str val))))
 
                    `(entry (% (heading