| 85 | } |
| 86 | |
| 87 | func buildUpdateDocumentStyleRequest(opts docsDocumentStyleOptions) (*docs.UpdateDocumentStyleRequest, error) { |
| 88 | style := &docs.DocumentStyle{} |
| 89 | fields := []string{} |
| 90 | |
| 91 | if strings.TrimSpace(opts.Mode) != "" { |
| 92 | style.DocumentFormat = &docs.DocumentFormat{DocumentMode: opts.Mode} |
| 93 | fields = append(fields, "documentFormat") |
| 94 | } |
| 95 | |
| 96 | // The Docs schema says pageSize/margins are not rendered in PAGELESS mode, |
| 97 | // but live Docs readback shows pageless table/content width still follows |
| 98 | // documentStyle.pageSize minus margins. Keep these flags explicit, not |
| 99 | // automatic, so --pageless never widens existing docs unless requested. |
| 100 | pageWidthRaw, pageHeightRaw, err := resolveDocsPageSize(opts.PageSize, opts.PageWidth, opts.PageHeight) |
| 101 | if err != nil { |
| 102 | return nil, err |
| 103 | } |
| 104 | |
| 105 | pageWidth, ok, err := parseDocsDimension("page-width", pageWidthRaw, false) |
| 106 | if err != nil { |
| 107 | return nil, err |
| 108 | } |
| 109 | if ok { |
| 110 | if style.PageSize == nil { |
| 111 | style.PageSize = &docs.Size{} |
| 112 | } |
| 113 | style.PageSize.Width = pageWidth |
| 114 | fields = append(fields, "pageSize.width") |
| 115 | } |
| 116 | |
| 117 | pageHeight, ok, err := parseDocsDimension("page-height", pageHeightRaw, false) |
| 118 | if err != nil { |
| 119 | return nil, err |
| 120 | } |
| 121 | if ok { |
| 122 | if style.PageSize == nil { |
| 123 | style.PageSize = &docs.Size{} |
| 124 | } |
| 125 | style.PageSize.Height = pageHeight |
| 126 | fields = append(fields, "pageSize.height") |
| 127 | } |
| 128 | |
| 129 | if err := setMarginDimension(&fields, "margin-left", "marginLeft", opts.MarginLeft, &style.MarginLeft); err != nil { |
| 130 | return nil, err |
| 131 | } |
| 132 | if err := setMarginDimension(&fields, "margin-right", "marginRight", opts.MarginRight, &style.MarginRight); err != nil { |
| 133 | return nil, err |
| 134 | } |
| 135 | if err := setMarginDimension(&fields, "margin-top", "marginTop", opts.MarginTop, &style.MarginTop); err != nil { |
| 136 | return nil, err |
| 137 | } |
| 138 | if err := setMarginDimension(&fields, "margin-bottom", "marginBottom", opts.MarginBottom, &style.MarginBottom); err != nil { |
| 139 | return nil, err |
| 140 | } |
| 141 | |
| 142 | if len(fields) == 0 { |
| 143 | return nil, usage("no document style changes requested") |
| 144 | } |